anchor.diff:      end,
       State;
   
  +%% In case of an emergency, we check immediately
  +handle_msg({emergency, LoadInfo, DirKey}, State) ->
  +    %% TODO just write directly to db instead
  +    post_load_to_directory(LoadInfo, DirKey),
  +    %% TODO Emergency Threshold has been already check at the node overloaded...
  +    EmergencyThreshold = State#state.threshold_emergency,
  +    case LoadInfo#node.utilization > EmergencyThreshold of
  +        true  ->
  +            MyDirKeys = State#state.my_dirs,
  +            directory_routine(DirKey, emergency);
  +        false -> State
  +    end;
  +
   handle_msg({directory_trigger}, State) ->
       trigger(directory_trigger),
  -    MyDirectories = State#state.my_dirs,
  -    %Reassignments = [balance(Dir) || Dir <- MyDirectories],
  -    %PeriodicThreshold =
  +    ?TRACE("~p My Directories: ~p~n", [self(), State#state.my_dirs]),
       %% Threshold k_p = Average laod in directory
       %% Threshold k_e = 1 meaning full capacity
       %% Upon receipt of load information:
  
positive.code: handle_dht_msg({lb_active, Msg}, DhtState) ->
      DhtState.
  
  request_dht_range() ->
      MyDHT = pid_groups:get_my(dht_node),
      comm:send_local(MyDHT, {get_state, comm:this(), my_range}).
  
negative.code:             end
      end.
  
  -spec get_all_directory_keys() ->  ?RT:key().
  get_all_directory_keys() ->
      [get_directory_key_by_number(N) || N <- lists:seq(1, ?NUM_DIRECTORIES)].
  
  -spec get_random_directory_key() ->  ?RT:key().
  get_random_directory_key() ->
      Rand = randoms:rand_uniform(1, ?NUM_DIRECTORIES+1),
      get_directory_key_by_number(Rand).
  
  -spec get_directory_key_by_number(pos_integer()) -> ?RT:key().
  get_directory_key_by_number(N) when N > 0 ->
      ?RT:hash_key("lb_active_dir" ++ int_to_str(N)).
  
  -spec post_load_to_directory(node(), directory_name()) -> ok.
  post_load_to_directory(Load, DirKey) ->
      TLog = api_tx:new_tlog(),
      case api_tx:read(TLog, DirKey) of
          {TLog2, {ok, Content}} ->
              ContentNew = dir_add_load(Load, Content),
              {TLog3, _Result} = api_tx:write(TLog2, DirKey, ContentNew),
              case api_tx:commit(TLog3) of
                  {ok} ->
                      ok;
                  {fail, abort, [DirKey]} ->
                      log:log(warn, "~p: Failed to write to directory, retrying...", [?MODULE]),
                      post_load_to_directory(Load, DirKey)
              end;
          {_TLog2, {fail, not_found}} ->
              log:log(warn, "~p: Directory not found while posting load. This should never happen...", [?MODULE]),
              ok
      end.
  
  -spec dir_add_load(node(), directory()) -> directory().
  dir_add_load(Load, Directory) ->
      Pool = Directory#directory.pool,
      PoolNew = gb_sets:add(Load, Pool),
      Directory#directory{pool = PoolNew}.
  
  -spec pop_load_in_directory(directory_name()) -> directory().
  pop_load_in_directory(DirKey) ->
      TLog = api_tx:new_tlog(),
      case api_tx:read(TLog, DirKey) of
          {TLog2, {ok, Directory}} ->
              case api_tx:req_list(TLog2, [{write, DirKey, dir_clear_load(Directory)}, {commit}]) of
                  {[], ok, ok} -> Directory;
                  _ -> pop_load_in_directory(DirKey)
              end;
          {_TLog2, {fail, not_found}} ->
              log:log(warn, "~p: Directory not found while posting load. This should never happen...", [?MODULE])
      end.
  
  -spec dir_clear_load(directory()) -> directory().
  dir_clear_load(Directory) ->
      Directory#directory{pool = gb_sets:new()}.
  
  dir_set_schedule(Schedule, Directory) ->
      Directory#directory{schedule = Schedule}.
  
  get_directory(DirKey) ->
      TLog = api_tx:new_tlog(),
      case api_tx:read(TLog, DirKey) of
          {TLog2, {ok, Directory}} -> 
              {TLog2, Directory};
          _ -> 
              log:log(warn, "~p: Directory not found while posting load. This should never happen...", [?MODULE]),
              get_directory(DirKey)
      end.
  
  -spec set_directory(api_tx:tlog(), directory()) -> ok | failed.
  set_directory(TLog, Directory) ->
      DirKey = Directory#directory.name,
      case api_tx:req_list(TLog, [{write, DirKey, Directory}, {commit}]) of
          {[], ok, ok} -> 
              ok;
          _  ->
              log:log(warn, "~p: Failed to save directory ~p because of failed transaction.", [?MODULE, DirKey]),
              failed
      end.
  
  %%%%%%%%%%%%
  %% State
  