anchor.diff:              Reason = proplists:get_value(<<"reason">>, Props),
               {{Id, Rev}, {ErrId, Reason}}
           end, ErrorsJson),
  -    {ok, ErrorsList};
  -write_docs(Db, Docs) ->
  +    case erase(docs_remaining) of
  +    undefined ->
  +        {ok, lists:flatten([ErrorsList|ErrorsAcc])};
  +    MoreDocs ->
  +        write_docs(Db, MoreDocs, [ErrorsList|ErrorsAcc])
  +    end;
  +write_docs(Db, Docs, _) ->
       couch_db:update_docs(Db, Docs, [], replicated_changes).
  
positive.code:         ok;
      {HighSeq, Docs} ->
          DocCount = length(Docs),
          try write_docs(Target, Docs) of
          {ok, []} ->
              Parent ! {update_stats, docs_written, DocCount};
          {ok, Errors} ->
  
negative.code: 
  -include("couch_db.hrl").
  
  -define (MAX_BYTES, 10000000).
  
  start_link(Parent, Target, Reader, _PostProps) ->
      {ok, spawn_link(fun() -> writer_loop(Parent, Reader, Target) end)}.
  
  make_chunk(Data) when is_list(Data) ->
      make_chunk(list_to_binary(Data));
  make_chunk(Data) ->
      Size = size(Data),
      {Size, [ibrowse_lib:dec2hex(8, Size), "\r\n", Data, "\r\n"]}.
  
  upload_docs({start, Docs}) ->
      {Size, Chunk} = make_chunk(<<"{\"new_edits\":false, \"docs\":[">>),
      {ok, Chunk, {continue, Docs, "", Size}};
  upload_docs({continue, Docs, _, ByteCount}) when ByteCount > ?MAX_BYTES ->
      put(docs_remaining, Docs),
      {ok, "2\r\n]}\r\n", last_chunk};
  upload_docs({continue, [Doc|Rest], Prepend, ByteCount}) ->
      JsonDoc = ?JSON_ENCODE(couch_doc:to_json_obj(Doc, [revs,attachments])),
      {Size, Chunk} = make_chunk([Prepend, JsonDoc]),
      {ok, Chunk, {continue, Rest, ",", ByteCount+Size}};
  upload_docs({continue, [], _, _}) ->
      {ok, "2\r\n]}\r\n", last_chunk};
  upload_docs(last_chunk) ->
      {ok, "0\r\n\r\n", finish};
  upload_docs(finish) ->
  