anchor.diff:      [exit(Pid, shutdown) || #job{pid=Pid} <- State#state.active],
       ok.
   
  -code_change(_, #state{waiting = [{_,_}|_] = W, active=A} = State, _) ->
  -    Waiting = [#job{name=Name, node=Node} || {Name,Node} <- W],
  -    Active = [#job{name=Name, node=Node, pid=Pid} || {Name,Node,Pid} <- A],
  -    {ok, State#state{active = Active, waiting = Waiting}};
  +code_change(_, #state{waiting = WaitingList} = State, _) ->
  +    {ok, State#state{waiting = from_list(WaitingList)}};
   
   code_change(_, State, _) ->
       {ok, State}.
   
  -handle_replication_exit(#state{waiting=[]} = State, Pid) ->
  -    NewActive = lists:keydelete(Pid, #job.pid, State#state.active),
  -    {noreply, State#state{active=NewActive, count=length(NewActive)}};
   handle_replication_exit(State, Pid) ->
       #state{active=Active, limit=Limit, dict=D, waiting=Waiting} = State,
       Active1 = lists:keydelete(Pid, #job.pid, Active),
  -    Count = length(Active1),
  -    NewState = if Count < Limit ->
  -        case next_replication(Active1, Waiting) of
  -        nil -> % all waiting replications are also active
  -            State#state{active = Active1, count = Count};
  -        {#job{name=DbName, node=Node} = Job, StillWaiting} ->
  -            NewPid = start_push_replication(Job),
  -            State#state{
  -                active = [Job#job{pid = NewPid} | Active1],
  -                count = Count+1,
  -                dict = dict:erase({DbName,Node}, D),
  -                waiting = StillWaiting
  -            }
  -        end;
  +    case is_empty(Waiting) of
       true ->
  -        State#state{active = Active1, count=Count}
  -    end,
  -    {noreply, NewState}.
  +        {noreply, State#state{active=Active1, count=length(Active1)}};
  +    _ ->
  +        Count = length(Active1),
  +        NewState = if Count < Limit ->
  +            case next_replication(Active1, Waiting) of
  +            nil -> % all waiting replications are also active
  +                State#state{active = Active1, count = Count};
  +            {#job{name=DbName, node=Node} = Job, StillWaiting} ->
  +                NewPid = start_push_replication(Job),
  +                State#state{
  +                  active = [Job#job{pid = NewPid} | Active1],
  +                  count = Count+1,
  +                  dict = dict:erase({DbName,Node}, D),
  +                  waiting = StillWaiting
  +                 }
  +            end;
  +        true ->
  +            State#state{active = Active1, count=Count}
  +        end,
  +        {noreply, NewState}
  +    end.
   
   start_push_replication(#job{name=Name, node=Node}) ->
       spawn_link(mem3_rep, go, [Name, Node]).
   
   add_to_queue(State, #job{name=DbName, node=Node} = Job) ->
  -    #state{dict=D, waiting=Waiting} = State,
  +    #state{dict=D, waiting=WQ} = State,
       case dict:is_key({DbName, Node}, D) of
       true ->
           State;
  
positive.code: -spec next_replication([#job{}], [#job{}]) -> {#job{}, [#job{}]} | nil.
  next_replication(Active, Waiting) ->
      Fun = fun(#job{name=S, node=N}) -> is_running(S,N,Active) end,
      case lists:splitwith(Fun, Waiting) of
      {_, []} ->
          nil;
      {Running, [Job|Rest]} ->
          {Job, Running ++ Rest}
      end.
  
  is_running(DbName, Node, ActiveList) ->
  
negative.code:     {reply, State#state.active, State};
  
  handle_call(get_queue, _From, State) ->
      {reply, to_list(State#state.waiting), State};
  
  handle_call(get_backlog, _From, #state{active=A, waiting=WQ} = State) ->
      CA = lists:sum([C || #job{count=C} <- A, is_integer(C)]),
      CW = lists:sum([C || #job{count=C} <- to_list(WQ), is_integer(C)]),
      {reply, CA+CW, State}.
  
  handle_cast({push, DbName, Node}, State) ->
  