anchor.diff:                              gen_server:cast(Pid, stop);
                           _ ->
                               ok
  -                    end;
  -                _ ->
  -                    ok
  +                    end,
  +                    State0#state{
  +                        proc_counts=dict:update_counter(Lang, -1, Counts)
  +                    };
  +                {ok, _} ->
  +                    State0
               end;
           _ ->
  -            ok
  +            State0
       end,
       {noreply, State};
   handle_cast(reload_config, State) ->
  
positive.code:     unlink(Pid),
      {ok, Proc}.
  
  assign_proc(Tab, Client, #proc{client=nil}=Proc0) ->
      Proc = Proc0#proc{client = erlang:monitor(process, Client)},
      ets:insert(Tab, Proc),
      Proc.
  
  return_proc(Tab, #proc{pid=Pid} = Proc) ->
      case is_process_alive(Pid) of true ->
          gen_server:cast(Pid, garbage_collect),
          ets:insert(Tab, Proc#proc{client=nil});
      false ->
          ets:delete(Tab, Pid)
      end.
  
  get_proc_config() ->
      Limit = config:get("query_server_config", "reduce_limit", "true"),
  
negative.code:     TeachFun = fun(Proc0, Acc) ->
          try
              {ok, Proc1} = teach_ddoc(DDoc, DDocKey, Proc0),
              {stop, assign_proc(State#state.tab, ClientPid, Proc1)}
          catch _:_ ->
              {ok, Acc}
          end
      end,
      Client = #client{from=From, lang=Lang, ddoc=DDoc, ddoc_key=DDocKey},
      find_proc(State, Client, [IterFun, TeachFun]);
  
  handle_call({get_proc, Lang}, From, State) ->
      {ClientPid, _} = From,
      IterFun = fun(Proc, _Acc) ->
          {stop, assign_proc(State#state.tab, ClientPid, Proc)}
      end,
      Client = #client{from=From, lang=couch_util:to_binary(Lang)},
      find_proc(State, Client, [IterFun]);
  
  handle_call({ret_proc, #proc{client=Ref, lang=Lang0} = Proc}, _From, State) ->
      erlang:demonitor(Ref, [flush]),
      Lang = couch_util:to_binary(Lang0),
      % We need to check if the process is alive here, as the client could be
      % handing us a #proc{} with a dead one.  We would have already removed the
      % #proc{} from our own table, so the alternative is to do a lookup in the
      % table before the insert.  Don't know which approach is cheaper.
      {reply, true, return_proc(State, Proc#proc{lang=Lang})};
  
  handle_call(_Call, _From, State) ->
      {reply, ignored, State}.
  
  handle_cast({os_proc_idle, Pid}, #state{tab=Tab, proc_counts=Counts}=State0) ->
      Limit = list_to_integer(
              config:get("query_server_config", "os_process_soft_limit", "100")),
      State = case ets:lookup(Tab, Pid) of
          [#proc{client=nil, lang=Lang}] ->
              case dict:find(Lang, Counts) of
                  {ok, Count} when Count > Limit ->
                      ?LOG_INFO("Closing idle OS Process: ~p", [Pid]),
                      ets:delete(Tab, Pid),
                      case is_process_alive(Pid) of
  