anchor.diff:      end.
   
   
  -enough(W, PW, NVal, NumPrimaryOkays, NumFallbackOkays, Errors) ->
  -    case PW of
  -        Val when is_integer(Val) andalso Val > 0 ->
  -            enough(PW, NumPrimaryOkays, NVal, Errors);
  -        _Rubbish ->
  -            enough(W, NumPrimaryOkays + NumFallbackOkays, NVal, Errors)
  -    end.
  -
  -enough(Threshold, Okays, TotalPossible, Errors) ->
  -    case Threshold =< Okays of
  -        true -> {true, ok};
  -        false ->
  -            NumErrors = length(Errors),
  -            case (TotalPossible - NumErrors) < Threshold of
  -                true -> {true, {error, too_many_fails}};
  -                false -> {false, noreply}
  -            end
  +enough(W, PW, _NVal, NumW, _NumPW, _NumErrors)  when W =< NumW, PW =< 0 ->
  +    true;
  +enough(W, PW, _NVal, NumW, NumPW, _NumErrors)   when W =< NumW, 0 < PW, PW =< NumPW ->
  +    true;
  +enough(W, PW, NVal, _NumW, _NumPW, NumErrors)   when PW =< 0, (NVal - NumErrors) < W ->
  +    true;
  +enough(_W, PW, NVal, _NumW, _NumPW, NumErrors)  when 0 < PW, (NVal - NumErrors) < PW ->
  +    true;
  +enough(_W, _PW, _NVal, _NumW, _NumPW, _NumErrors) ->
  +    false.
  +
  +response(W, PW, _NVal, NumW, _NumPW, _Errors, _NumErrors)   when W =< NumW, PW =< 0 ->
  +    ok;
  +response(W, PW, _NVal, NumW, NumPW, _Errors, _NumErrors)    when W =< NumW, 0 < PW, PW =< NumPW ->
  +    ok;
  +response(W, PW, NVal, NumW, _NumPW, Errors, NumErrors)      when PW =< 0, (NVal - NumErrors) < W ->
  +    overload_trumps(Errors, {error, {w_val_unsatisfied, W, NumW}});
  +response(_W, PW, NVal, _NumW, NumPW, Errors, NumErrors)     when 0 < PW, (NVal - NumErrors) < PW ->
  +    overload_trumps(Errors, {error, {pw_val_unsatisfied, PW, NumPW}}).
  +
  +
  +overload_trumps(Errors, Default) ->
  +    case lists:member({error, overload}, Errors) of
  +        true ->
  +            {error, overload};
  +        _->
  +            Default
       end.
   
   reply(From, ReqId, Term) ->
  
positive.code:             end,
              {noreply, NewState}
      end;
  handle_info(Msg, State) ->
      lager:error("Unexpected message sent to ~p: ~p", [?MODULE, Msg]),
      {noreply, State}.
  
  terminate(_Reason, _State) ->
  
negative.code:                         {PrimaryOkays + 1, FallbackOkays, Errors};
                      {ok, fallback} ->
                          {PrimaryOkays, FallbackOkays + 1, Errors};
                      {{error, Reason}, _} ->
                          {PrimaryOkays, FallbackOkays, [Reason | Errors]}
                  end,
              % TODO use riak_kv_put_core here instead
              case enough(W, PW, NVal, PrimaryOkays1 + FallbackOkays1, PrimaryOkays1, length(Errors1)) of
                  true ->
                      {_, NewState} = erase_request_record(ReqId, State),
                      reply(From, ReqId, response(W, PW, NVal, PrimaryOkays1 + FallbackOkays1, PrimaryOkays1, Errors1, length(Errors)));
                  false ->
                      NewRec = Rec#rec{
                          primary_okays = PrimaryOkays1,
                          fallback_okays = FallbackOkays1,
  