anchor.diff:          writer_loop(Parent, Reader, Target)
       end.
   
  -write_docs(#http_db{} = Db, Docs, ErrorsAcc) ->
  -    ErrorsJson = couch_rep_httpc:request(Db#http_db{
  +write_docs(#http_db{} = Db, Docs) ->
  +    {Worker, Ref} = spawn_monitor(fun() -> encoding_worker(Docs) end),
  +    Pid = spawn_link(fun() -> Worker ! {self(),next_doc}, middle_man(Worker) end),
  +    Request = Db#http_db{
           resource = "_bulk_docs",
           method = post,
  -        body = {fun upload_docs/1, {start, self(), Docs}},
  +        body = {fun upload_docs/1, {start, Pid}},
           headers = [{"transfer-encoding", "chunked"} | Db#http_db.headers]
  -    }),
  +    },
  +    ErrorsJson = request_loop(Ref, Request, []),
       ErrorsList =
       lists:map(
           fun({Props}) ->
  
positive.code:             Reason = proplists:get_value(<<"reason">>, Props),
              {{Id, Rev}, {ErrId, Reason}}
          end, ErrorsJson),
      receive
      {docs_remaining, 0} ->
          {ok, lists:flatten([ErrorsList|ErrorsAcc])};
      {docs_remaining, N} ->
          MoreDocs = lists:nthtail(length(Docs)-N, Docs),
          write_docs(Db, MoreDocs, [ErrorsList|ErrorsAcc])
      end;
  write_docs(Db, Docs, _) ->
      couch_db:update_docs(Db, Docs, [], replicated_changes).
  
negative.code:         ok;
      {HighSeq, Docs} ->
          DocCount = length(Docs),
          try write_docs(Target, Docs) of
          {ok, []} ->
              Parent ! {update_stats, docs_written, DocCount};
          {ok, Errors} ->
  