anchor.diff:          <<"triggered">> ->
               maybe_start_replication(State, DbName, DocId, JsonRepDoc);
           <<"completed">> ->
  -            replication_complete(DocId),
  +            replication_complete(DbName, DocId),
               State;
           <<"error">> ->
  -            case ets:lookup(?DOC_TO_REP, DocId) of
  +            case ets:lookup(?DOC_TO_REP, {DbName, DocId}) of
               [] ->
                   maybe_start_replication(State, DbName, DocId, JsonRepDoc);
               _ ->
  
positive.code:             max_retries = State#state.max_retries
          },
          true = ets:insert(?REP_TO_STATE, {RepId, RepState}),
          true = ets:insert(?DOC_TO_REP, {DocId, RepId}),
          twig:log(notice,"Attempting to start replication `~s` (document `~s`).",
              [pp_rep_id(RepId), DocId]),
          Pid = spawn_link(fun() -> start_replication(Rep, 0) end),
  
negative.code:         #rep_state{} ->
              ok
          end,
          true = ets:delete(?DOC_TO_REP, {DbName, DocId});
      _ ->
          ok
      end.
  
  
  rep_doc_deleted(DbName, DocId) ->
      case ets:lookup(?DOC_TO_REP, {DbName, DocId}) of
      [{{DbName, DocId}, RepId}] ->
          couch_replicator:cancel_replication(RepId),
          true = ets:delete(?REP_TO_STATE, RepId),
          true = ets:delete(?DOC_TO_REP, {DbName, DocId}),
          twig:log(notice, "Stopped replication `~s` because replication document `~s`"
              " was deleted", [pp_rep_id(RepId), DocId]);
      [] ->
  