anchor.diff:  %% @doc Message handler during start up phase (will change to on_active/2 when a
   %%      'activate_clustering' message is received).
   -spec on_inactive(message(), state_inactive()) -> state_inactive();
  -                ({activate_clustering}, state_inactive()) -> {'$gen_component', [{on_handler, Handler::gen_component:handler()}], State::state_active()}.
  -on_inactive({activate_clustering},
  -            {inactive, QueuedMessages, ResetTriggerState, ClusterTriggerState}) ->
  +                ({activate_clustering}, state_inactive())
  +            -> {'$gen_component', [{on_handler, Handler::gen_component:handler()}], State::state_active()}.
  +on_inactive({activate_clustering}, #state_inactive{
  +                                    queued_messages=QueuedMessages
  +                                    ,reset_trigger_state=ResetTriggerState
  +                                    ,cluster_trigger_state=ClusterTriggerState
  +                                    ,radius=R
  +                                }) ->
       log:log(info, "[ Clustering ~.0p ] activating...~n", [comm:this()]),
       ResetTriggerState2 = trigger:now(ResetTriggerState),
       ClusterTriggerState2 = trigger:now(ClusterTriggerState),
       msg_queue:send(QueuedMessages),
  -    gen_component:change_handler({dc_centroids:empty_centroids_list(), 0, ResetTriggerState2, ClusterTriggerState2},
  -                                 fun ?MODULE:on_active/2);
  -
  -on_inactive(Msg = {query_clustering, _Pid},
  -            {inactive, QueuedMessages, ResetTriggerState, ClusterTriggerState}) ->
  -    {inactive, msg_queue:add(QueuedMessages, Msg), ResetTriggerState, ClusterTriggerState};
  -
  -on_inactive({query_epoch, _Pid} = Msg, 
  -            {inactive, QueuedMessages, ResetTriggerState, ClusterTriggerState}) ->
  -    {inactive, msg_queue:add(QueuedMessages, Msg), ResetTriggerState, ClusterTriggerState};
  -
  -on_inactive({web_debug_info, Requestor},
  -            {inactive, QueuedMessages, _ResetTriggerState, _ClusterTriggerState} = State) ->
  +    StateActive = #state_active{
  +        centroids = dc_centroids:empty_centroids_list()
  +        , reset_trigger_state = ResetTriggerState2
  +        , cluster_trigger_state = ClusterTriggerState2
  +        , radius=R
  +    },
  +    gen_component:change_handler(StateActive, fun ?MODULE:on_active/2)
  +    ;
  +
  +on_inactive(Msg = {query_clustering, _Pid}, #state_inactive{queued_messages=QueuedMessages} = State) ->
  +    State#state_inactive{queued_messages=msg_queue:add(QueuedMessages, Msg)}
  +    ;
  +
  +on_inactive({query_epoch, _Pid} = Msg, #state_inactive{queued_messages=Q} = State) ->
  +    State#state_inactive{queued_messages=msg_queue:add(Q, Msg)}
  +    ;
  +
  +on_inactive({web_debug_info, Requestor}, #state_inactive{queued_messages=Q} = State) ->
       % get a list of up to 50 queued messages to display:
       MessageListTmp = [{"", webhelpers:safe_html_string("~p", [Message])}
  -                  || Message <- lists:sublist(QueuedMessages, 50)],
  -    MessageList = case length(QueuedMessages) > 50 of
  +                  || Message <- lists:sublist(Q, 50)],
  +    MessageList = case length(Q) > 50 of
                         true -> lists:append(MessageListTmp, [{"...", ""}]);
                         _    -> MessageListTmp
                     end,
  
positive.code: %% @doc Message handler when the module is fully initialized.
  -spec on_active(Message::message(), State::state_active()) -> state_active();
           ({deactivate_clustering}, state_active()) -> {'$gen_component', [{on_handler, Handler::gen_component:handler()}], State::state_inactive()}.
  on_active({deactivate_clustering},
            {_Centroids, ResetTriggerState, ClusterTriggerState}) ->
      log:log(info, "[ Clustering ~.0p ] deactivating...~n", [comm:this()]),
      gen_component:change_handler({inactive, msg_queue:new(), ResetTriggerState, ClusterTriggerState},
                                   fun ?MODULE:on_inactive/2);
  
  % ignore activate_clustering messages in active state
  % note: remove this if the clustering process is to be deactivated on leave (see
  
negative.code: on_active({activate_clustering}, State) ->
      State;
      
  on_active({start_clustering_shuffle}, #state_active{cluster_trigger_state = C} = State) ->
      % start new clustering shuffle -> gossip communication
      NewClusterTriggerState = trigger:next(C),
      cyclon:get_subset_rand(1),
      State#state_active{cluster_trigger_state=NewClusterTriggerState}
      ;
  
  % ask vivaldi for network coordinate
  on_active({reset_clustering}
            , #state_active{reset_trigger_state = ResetTriggerState} = State) ->
      NewResetTriggerState = trigger:next(ResetTriggerState),
      vivaldi:get_coordinate(),
      State#state_active{reset_trigger_state=NewResetTriggerState}
      ;
  
  % reset the local state and start a new epoche
  on_active({vivaldi_get_coordinate_response, Coordinate, _Confidence}
             , #state_active{local_epoch=Epoch} = State) ->
      State#state_active{
          local_epoch=Epoch + 1
          , centroids=[dc_centroids:new(Coordinate, 1.0)]
      }
      ;
  
  on_active({cy_cache, []}, State)  ->
      % ignore empty cache from cyclon
      State;
  
  % got random node from cyclon
  on_active({cy_cache, [Node] = _Cache}
            , #state_active{centroids=C, local_epoch=E} = State) ->
      %io:format("~p~n",[_Cache]),
      comm:send(node:pidX(Node), {clustering_shuffle, comm:this(), C, E},
                [{group_member, dc_clustering}]),
      State;
  
  