anchor.diff:                      tree_from_file(Device, Counter + 1, LeavesLeft - 1, Tree1, Path0)
               end
       end.
  +   
  +path_from_tree_dict(Tree, Leaves) ->
  +    lists:foldl(fun({Id, Row}, Paths0) ->
  +                    case (Id >= Leaves) of
  +                        true ->
  +                            {OneHopPath, _} = lists:foldl(fun(Elem, {Acc, C}) ->
  +                                                            case Elem of
  +                                                                -1 ->
  +                                                                    {Acc, C+1};
  +                                                                _ ->
  +                                                                    {Acc ++ [C], C+1}
  +                                                             end
  +                                                           end, {[], 0}, Row),
  +                            dict:store(Id, OneHopPath, Paths0);
  +                        false ->
  +                            Paths0
  +                    end
  +                end, dict:new(), dict:to_list(Tree)).
   
   is_leaf(Id, Total) ->
       Id<Total.
  
positive.code:                                     case interested(Id, Key, MyId, S0) of
                                          true ->
                                              case dict:find(Id, Map) of
                                                  {ok, Value} -> Acc ++ [Value];
                                                  error -> Acc
                                              end;
                                          false ->
  
negative.code:     end,
      file:close(TreeFile),
      {ok, S1#state{map=dict:new()}}.
  
  handle_call({set_treedict, Tree, Leaves}, _From, S0) ->
      Paths = path_from_tree_dict(Tree, Leaves),
      {reply, ok, S0#state{paths=Paths, tree=Tree, nleaves=Leaves}};
  
  handle_call({set_groupsdict, RGroups}, _From, S0) ->
      {reply, ok, S0#state{groups=RGroups}};
  
  handle_call({new_groupsfile, File}, _From, S0) ->
      {ok, GroupsFile} = file:open(File, [read]),
      RGroups = replication_groups_from_file(GroupsFile, dict:new()),
      file:close(GroupsFile),
      {reply, ok, S0#state{groups=RGroups}};
  
  handle_call({new_treefile, File}, _From, _S0) ->
      {ok, TreeFile} = file:open(File, [read]),
      case file:read_line(TreeFile) of
          eof ->
              lager:error("Empty file: ~p", [File]),
              S1 = #state{paths=dict:new(), tree=dict:new(), nleaves=0};
          {error, Reason} ->
              lager:error("Problem reading ~p file, reason: ~p", [File, Reason]),
              S1 = #state{paths=dict:new(), tree=dict:new(), nleaves=0};
          {ok, Line} ->
              {NLeaves, []} = string:to_integer(hd(string:tokens(Line, "\n"))),
              {Tree, Paths} = tree_from_file(TreeFile, 0, NLeaves, dict:new(), dict:new()),
              S1 = #state{paths=Paths, tree=Tree, nleaves=NLeaves}
      end,
      file:close(TreeFile),
      {reply, ok, S1};
  
  handle_call({set_myid, MyId}, _From, S0) ->
      {reply, ok, S0#state{myid=MyId}};
  