anchor.diff:          true = ets:insert(?DOC_TO_REP, {DocId, RepId}),
           ?LOG_INFO("Attempting to start replication `~s` (document `~s`).",
               [pp_rep_id(RepId), DocId]),
  -        Server = self(),
  -        Pid = spawn_link(fun() -> start_replication(Server, Rep, 0) end),
  +        Pid = spawn_link(fun() -> start_replication(Rep, 0) end),
           State#state{rep_start_pids = [Pid | State#state.rep_start_pids]};
       #rep_state{rep = #rep{doc_id = DocId}} ->
           State;
  
positive.code:     end.
  
  
  start_replication(Server, #rep{id = RepId} = Rep, Wait) ->
      ok = timer:sleep(Wait * 1000),
      case (catch couch_replicator:async_replicate(Rep)) of
      {ok, _} ->
          ok = gen_server:call(Server, {rep_started, RepId}, infinity);
      Error ->
          replication_error(Rep, Error)
      end.
  
negative.code:     ?LOG_ERROR("Error in replication `~s` (triggered by document `~s`): ~s"
          "~nRestarting replication in ~p seconds.",
          [pp_rep_id(RepId), DocId, to_binary(error_reason(Error)), Wait]),
      Pid = spawn_link(fun() -> start_replication(Rep, Wait) end),
      State#state{rep_start_pids = [Pid | State#state.rep_start_pids]}.
  
  
  