anchor.diff:      end,
       {noreply, State#state{works=Works1}};
   
  -handle_info({'DOWN', _MRef, process, Pid, _Reason}, #state{services=Srvs}=State) ->
  +handle_info({'DOWN', _MRef, process, Pid, _Reason}, State) ->
  +    #state{name=Name, services=Srvs, works=Works} = State,
       case maps:find(Pid, Srvs) of
           {ok, {SrvId, CallPids}} ->
  -            lager:warning("Service ~p (~p) down", [SrvId, SrvId:name()]),
  -            State1 = do_service_down(CallPids, State),
  -            State2 = State1#state{services=maps:remove(Pid, Srvs)},
  -            {noreply, State2};
  -        false ->
  -            {noreply, do_call_down(Pid, State)}
  +            % A service is down
  +            lager:info("Service ~p (~p) down at ~p. Calls: ~p", 
  +                          [SrvId, SrvId:name(), Name, CallPids]),
  +            lists:foreach(fun(CallPid) -> gen_server:cast(CallPid, stop) end, CallPids),
  +            State1 = State#state{services=maps:remove(Pid, Srvs)},
  +            {noreply, State1};
  +        error ->
  +            % A call is down
  +            State1 = remove_call(Pid, State),
  +            State2 = case maps:find(Pid, Works) of
  +                {ok, {SrvId, CallId, WorkList}} -> 
  +                    % We had pending work for this process.
  +                    % Actually, we know the process has stopped normally before processing
  +                    % these requests (it hasn't failed due to an error).
  +                    % If the process had failed due to an error processing the work,
  +                    % the "received work" message would have been received an the work will
  +                    % not be present in Works.
  +                    St = State1#state{works=maps:remove(Pid, Works)},
  +                    resend_worklist(SrvId, CallId, lists:reverse(WorkList), St);
  +                error ->
  +                    State1
  +            end,
  +            {noreply, State2}
       end;
   
   handle_info(Info, State) -> 
  
positive.code:     ok.
  
  send_work_async(Name, SrvId, CallId, Work) ->
      case find(Name, SrvId, CallId) of
          {ok, CallPid} -> 
              nksip_call_srv:async_work(CallPid, Work);
          not_found -> 
  
negative.code: 
  
  %% @private
  -spec find_call_pid(atom(), nksip:srv_id(), nksip:call_id()) ->
      {ok, pid()} | not_found.
  
  find_call_pid(Name, SrvId, CallId) ->
      case ets:lookup(Name, {call, SrvId, CallId}) of
          [{_, CallPid}] -> {ok, CallPid};
          [] -> not_found
      end.
  
  %% @private
  work_id(Tuple) when is_tuple(Tuple) -> element(1, Tuple);
  work_id(Other) -> Other.
  
  
  
  %% @private
  -spec save_call(nksip:srv_id(), pid(), nksip:call_id(), pid(), #state{}) ->
      #state{}.
  
  save_call(SrvId, SrvPid, CallId, CallPid, #state{name=Name, services=Srvs}=State) ->
      erlang:monitor(process, CallPid),
      RefId = {call, SrvId, CallId},
      true = ets:insert(Name, [{RefId, CallPid}, {CallPid, RefId}]),
      OldCalls = case maps:find(SrvPid, Srvs) of
          {ok, {SrvId, OldCalls0}} -> 
              OldCalls0;
          error -> 
              monitor(process, SrvPid),
              []
      end,
      Srvs1 = maps:put(SrvPid, {SrvId, [CallPid|OldCalls]}, Srvs),
      State#state{services=Srvs1}.
  
  
  %% @private
  -spec remove_call(pid(), #state{}) ->
      #state{}.
  
  remove_call(CallPid, #state{pos=Pos, name=Name, services=Srvs}=State) ->
      case ets:lookup(Name, CallPid) of
          [{CallPid, RefId}] ->
              {_, SrvId, CallId} = RefId,
              ?debug(SrvId, CallId, "Router ~p unregistering call", [Pos]),
              ets:delete(Name, CallPid), 
              ets:delete(Name, RefId),
              case whereis(SrvId) of
                  undefined ->
                      State;
                  SrvPid ->
                      case maps:find(SrvPid, Srvs) of
                          {ok, {SrvId, CallPids}} ->
                              CallPids1 = CallPids -- [CallPid],
                              Srvs1 = maps:put(SrvPid, {SrvId, CallPids1}, Srvs),
                              State#state{services=Srvs1};
                          error ->
                              % It could be already deleted
                              State
                      end
              end;
          [] ->
              State
      end.
  
  
  %% @private
  