anchor.diff:            fun ({Id, [Rev]}, Acc) ->
                     {VBucket, _Node} = cb_util:vbucket_from_id(Bucket, Id),
   
  -                  case ns_memcached:get_meta(Bucket, Id, VBucket) of
  -                      {memcached_error, key_enoent, _} ->
  +                  case capi_utils:get_meta(Bucket, VBucket, Id, UserCtx) of
  +                      {error, enoent} ->
                             [{Id, [Rev], []} | Acc];
  -                      {memcached_error, not_my_vbucket, _} ->
  +                      {error, not_my_vbucket} ->
                             throw({bad_request, not_my_vbucket});
  -                      {ok, _, _, {revid, OurRev}} ->
  +                      {ok, OurRev, _Deleted, _Props} ->
  +                          %% we do not have any information about deletedness of
  +                          %% the remote side thus we use only revisions to
  +                          %% determine a winner
                             case winner(Rev, OurRev) of
                                 ours ->
                                     Acc;
  
positive.code:     Errors =
          lists:foldr(
            fun (#doc{id = Id, revs = {Pos, [RevId | _]}} = Doc, ErrorsAcc) ->
                    case do_update_replicated_doc(Bucket, Doc) of
                        ok ->
                            ErrorsAcc;
                        {error, Error} ->
  
negative.code:             theirs
      end.
  
  do_update_replicated_doc(Bucket, UserCtx,
                           #doc{id = Id, revs = {Pos, [RevId | _]},
                                body = Body, deleted = Deleted} = _Doc) ->
      {VBucket, _Node} = cb_util:vbucket_from_id(Bucket, Id),
      Json = ?JSON_ENCODE(Body),
      Rev = {Pos, RevId},
      do_update_replicated_doc_loop(Bucket, UserCtx, VBucket,
                                    Id, Rev, Json, Deleted).
  
  do_update_replicated_doc_loop(Bucket, UserCtx, VBucket, DocId,
                                {DocSeqNo, DocRevId} = DocRev,
                                DocJson, DocDeleted) ->
      RV =
          case capi_utils:get_meta(Bucket, VBucket, DocId, UserCtx) of
              {error, enoent} ->
                  case DocDeleted of
                      true ->
                          %% TODO: we must preserve source revision here
                          ok;
                      false ->
                          do_add_with_meta(Bucket, DocId, VBucket, DocJson, DocRev)
                  end;
              {error, not_my_vbucket} ->
                  {error, {bad_request, not_my_vbucket}};
              {ok, {OurSeqNo, OurRevId}, Deleted, Props} ->
                  DocRevExt = {DocSeqNo, not(DocDeleted), DocRevId},
                  OurRevExt = {OurSeqNo, not(Deleted), OurRevId},
  
                  case winner(DocRevExt, OurRevExt) of
                      ours ->
                          ok;
                      theirs ->
                          case DocDeleted of
                              true ->
                                  case Deleted of
                                      true ->
                                          %% TODO: we must preserve winning
                                          %% revision here
                                          ok;
                                      false ->
                                          {cas, CAS} = lists:keyfind(cas, 1, Props),
                                          do_delete(Bucket, DocId, VBucket, CAS)
                                  end;
                              false ->
                                  {cas, CAS} = lists:keyfind(cas, 1, Props),
                                  do_set_with_meta(Bucket, DocId, VBucket,
                                                   DocJson, DocRev, CAS)
                          end
  