anchor.diff:      gen_server:cast(statser_router, {line, Metric, Value, TS}).
   
   
  -calculate_timer([], _Samples) -> null;
  -calculate_timer(Values, Samples) ->
  +calculate_timer([]) ->
  +    {0, 0, 0, 0, 0, 0, 0};
  +calculate_timer(Values) ->
       Sorted = lists:sort(Values),
       Min = hd(Sorted),
  -    {Sums, SquaredSums, Len, Sum, SquaredSum} = walk_values(Sorted),
  +    {Sum, SquaredSum, Len} = walk_values(Sorted),
       Mean = Sum / Len,
       {StdDev, Max} = stddev_max(Mean, Sorted),
       Median = statser_processor:median(Sorted),
  -    {Min, Max, Mean, Median, StdDev, Sums, SquaredSums, Len, Sum, SquaredSum}.
  +    {Min, Max, Mean, Median, StdDev, Sum, SquaredSum}.
   
   
   walk_values([V | Vs]) ->
  -    walk_values([V], [V * V], 1, Vs).
  -
  -walk_values([A | _] = As, [B | _] = Bs, Len, []) ->
  -    {lists:reverse(As), lists:reverse(Bs), Len, A, B};
  -walk_values([A | _] = As, [B | _] = Bs, Len, [X | Xs]) ->
  -    walk_values([A + X | As], [B + X * X | Bs], Len+1, Xs).
  +    walk_values(V, V * V, 1, Vs).
  +
  +walk_values(A, B, Len, []) ->
  +    {A, B, Len};
  +walk_values(A, B, Len, [X | Xs]) ->
  +    walk_values(A + X, B + X * X, Len+1, Xs).
   
   
   stddev_max(Mean, Values) ->
  
positive.code: init(Port) ->
      lager:info("starting UDP listener at port ~w", [Port]),
  
      gen_server:cast(self(), accept),
      {ok, #state{port=Port,
                  counters=maps:new(),
                  timers=maps:new(),
                  gauges=maps:new(),
  
negative.code: %%                                  {stop, Reason, State}
  %% @end
  %%--------------------------------------------------------------------
  handle_cast(accept, #state{port=Port, interval=Interval} = State) ->
      Self = self(),
      {ok, Socket} = gen_udp:open(Port, [binary, {active, false}]),
      lager:info("UDP listener opened port at ~w [~p]", [Port, Socket]),
  
      % TODO: maybe we want to synchronize the flush interval with
      % the wall clock time matching with the graphite aggregation
      {ok, Timer} = timer:send_interval(Interval, flush),
  
      % TODO: handle exit/failure
      spawn_link(?MODULE, listen, [Self, Socket]),
      {noreply, State#state{timer=Timer}};
  
  handle_cast(_Msg, State) ->
      {noreply, State}.
  