anchor.diff:      cancel_timer(TRef),
       _ = vmq_exo:incr_connect_received(),
       %% the client is allowed "grace" of a half a time period
  -    KKeepAlive = 1500 * KeepAlive,
  -    set_keepalive_timer(KKeepAlive),
  +    set_keepalive_timer(KeepAlive),
       check_connect(Frame, incr_msg_recv_cnt(
  -                           State#state{keep_alive=KKeepAlive,
  +                           State#state{last_time_active=os:timestamp(),
  +                                       keep_alive=KeepAlive,
                                          keep_alive_tref=undefined}));
   wait_for_connect(close_timeout, State) ->
       lager:debug("[~p] stop due to timeout~n", [self()]),
  
positive.code:     end.
  
  msg_in(Msg, SessionState) ->
     case in(Msg, SessionState) of
         {stop, Reason, Out} ->
             {stop, Reason, serialise([Out])};
         {NewSessionState, {throttle, Out}} ->
  
negative.code: incr_cnt(IncrV, {Avg, Total, [V|Vals]}) ->
      {Avg, Total + IncrV, [V + IncrV|Vals]}.
  
  set_last_time_active(true, State) ->
      Now = os:timestamp(),
      maybe_trigger_counter_update(Now, State#state{last_time_active=Now});
  set_last_time_active(false, State) ->
      maybe_trigger_counter_update(os:timestamp(), State).
  
  maybe_trigger_counter_update({MSecs, Secs, _}, #state{last_trigger={MSecs, Secs, _}} = State) ->
      %% still in the same second resolution
      State;
  maybe_trigger_counter_update(Now, State) ->
      trigger_counter_update(State#state{last_trigger=Now}).
  
  trigger_counter_update(State) ->
      #state{recv_cnt=RecvCnt,
  