anchor.diff:                         S#state.waiting),
       Monitors = gb_sets:add(Ref, S#state.monitors),
       NewState = S#state{waiting=Waiting, monitors=Monitors},
  -    {noreply, NewState, get_timeout(NewState)};
  +    {NewState1, Sleep} = prepare_sleep(NewState),
  +    {noreply, NewState1, Sleep};
  +
   handle_call({done, UUID}, _From, S=#state{}) ->
  -    {reply, lmq_lib:done(S#state.name, UUID), S, get_timeout(S)};
  +    {State, Sleep} = prepare_sleep(S),
  +    {reply, lmq_lib:done(S#state.name, UUID), State, Sleep};
  +
   handle_call({retain, UUID}, _From, S=#state{props=Props}) ->
       R = lmq_lib:retain(S#state.name, UUID, proplists:get_value(timeout, Props)),
  -    {reply, R, S, get_timeout(S)};
  +    {State, Sleep} = prepare_sleep(S),
  +    {reply, R, State, Sleep};
  +
   handle_call({release, UUID}, _From, S=#state{}) ->
  -    {reply, lmq_lib:release(S#state.name, UUID), S, get_timeout(S)};
  +    {State, Sleep} = prepare_sleep(S),
  +    {reply, lmq_lib:release(S#state.name, UUID), State, Sleep};
  +
   handle_call(stop, _From, State) ->
       {stop, normal, ok, State}.
   
  
positive.code:         false ->
              S
      end,
      {noreply, NewState, get_timeout(NewState)};
  handle_info(Msg, State) ->
      io:format("Unknown message received: ~p~n", [Msg]),
      {noreply, State}.
  
negative.code: handle_info(timeout, S=#state{}) ->
      NewState = maybe_push_message(S),
      lager:debug("number of waitings: ~p", [queue:len(NewState#state.waiting)]),
      {State, Sleep} = prepare_sleep(NewState),
      {noreply, State, Sleep};
  
  handle_info({'DOWN', Ref, process, _Pid, _}, S=#state{monitors=M}) ->
      NewState = case gb_sets:is_member(Ref, M) of
          true ->
  