anchor.diff:      DefaultIncl2 = [filename:join(Dir, X) || X <- DefaultIncl1],
       Includes = SearchPaths ++ DefaultIncl2, 
       File = filename:join(Dir, Mod++".erl"),
  +    Files = refac_util:expand_files(SearchPaths, ".erl"),
  +    ModNames = [list_to_atom(M) || {M, _} <- refac_util:get_modules_by_file(Files)],
       {ok, {AnnAST, Info}} =refac_util:parse_annotate_file(File, true, Includes),
       ImportedMods = case lists:keysearch(imports,1, Info) of 
   		       {value, {imports, Imps}} -> lists:map(fun({M, _Funs}) -> M end, Imps);
   		       false  -> []
   		   end,
  -    CalledMods = collect_called_modules(AnnAST),
  +    CalledMods = collect_called_modules(AnnAST, ModNames),
  +    ?debug("Called modules:\n~p\n", [CalledMods]), 
       {called_modules, ImportedMods++CalledMods}.
   
  -%%-spec(collect_called_modules(AnnAST::syntaxTree()) ->
  -%%	     [modulename()]).
  +
   collect_called_modules(AnnAST) ->
  -    Fun = fun(T, S) ->
  +    element(1, collect_called_modules(AnnAST, [])).
  +
  +-spec(collect_called_modules(AnnAST::syntaxTree(), ModNames::[atom()]) ->[modulename()]).
  +collect_called_modules(AnnAST, ModNames) ->
  +    ?debug("ModNames:\n~p\n", [ModNames]),
  +    Fun = fun(T, {S1, S2}) ->
   		  case refac_syntax:type(T) of 
  +		      function -> {S1, S2++refac_rename_fun:collect_atoms(T, ModNames)};
   		      application ->
   			  Op = refac_syntax:application_operator(T),
   			  case lists:keysearch(fun_def, 1, refac_syntax:get_ann(Op)) of 
   			      {value, {fun_def, {M, F, A, _, _}}} ->
  -				S1 = ordsets:add_element(M, S),
  -				SpecialFuns1 = [{erlang,apply,3},{erlang, spawn,3},{erlang, spawn_link,3}, 
  -						{erlang, spawn_monitor, 3}, {erlang, spawn_opt, 4}],
  -				SpecialFuns2 = [{erlang, spawn, 4}, {erlang,spawn_link, 4}, {erlang, spawn_opt, 5}],
  -				case lists:member({M, F, A}, SpecialFuns1) of 
  -				    true ->
  -					Args = refac_syntax:application_arguments(T),
  -					M1 = hd(Args),
  -					case refac_util:try_evaluation([refac_syntax:revert(M1)]) of
  -					    {value, M} -> ordsets:add_element(M, S1);
  -					    _ -> S1
  -					end;
  -				    false ->
  -					case lists:member({M, F, A}, SpecialFuns2) of 
  -					    true ->
  -						Args = refac_syntax:application_arguments(T),
  -						M1 = element(2,list_to_tuple(Args)),
  -						case refac_util:try_evaluation([refac_syntax:revert(M1)]) of
  -						    {value, M2} -> ordsets:add_element(M2, S1);
  -						    _ -> S1
  -						end;
  -					    _ -> S1
  -					end
  -				end;
  -			      _ -> S
  +				  S = ordsets:add_element(M, S1),
  +				  SpecialFuns1 = [{erlang,apply,3},{erlang, spawn,3},{erlang, spawn_link,3}, 
  +						  {erlang, spawn_monitor, 3}, {erlang, spawn_opt, 4}],
  +				  SpecialFuns2 = [{erlang, spawn, 4}, {erlang,spawn_link, 4}, {erlang, spawn_opt, 5}],
  +				  case lists:member({M, F, A}, SpecialFuns1) of 
  +				      true ->
  +					  Args = refac_syntax:application_arguments(T),
  +					  M1 = hd(Args),
  +					  case refac_util:try_evaluation([refac_syntax:revert(M1)]) of
  +					      {value, M} -> 
  +						  {ordsets:add_element(M, S), S2};
  +					      _ -> {S, S2}
  +					  end;
  +				      false ->
  +					  case lists:member({M, F, A}, SpecialFuns2) of 
  +					      true ->
  +						  Args = refac_syntax:application_arguments(T),
  +						  M1 = element(2,list_to_tuple(Args)),
  +						  case refac_util:try_evaluation([refac_syntax:revert(M1)]) of
  +						      {value, M2} -> 
  +							  {ordsets:add_element(M2, S), S2};
  +						      _ -> {S, S2}
  +						  end;
  +					      _ -> {S, S2}
  +					  end
  +				  end;
  +			      _ -> {S1, S2}
   			  end;
  -		      _ -> S		  
  +		      _ -> {S1, S2}
   		  end
   	  end,
  -     lists:usort(refac_syntax_lib:fold(Fun, [], AnnAST)).
  +    {S1, S2} =refac_syntax_lib:fold(Fun, {[],[]}, AnnAST),
  +    ?debug("S1S2:\n~p\n", [{S1, S2}]),
  +    R1 = [{Pos, Name}|| {atom, Pos, Name} <- S2],
  +    R2 = [{Pos, Name}||{_,Pos,Name} <- lists:filter(fun (X) ->
  +							    case X of
  +								{atom, _X, _} -> false;
  +								_ -> true
  +							    end
  +						    end,
  +						    S2)],
  +    ?debug("R1R2:\n~p\n", [{R1, R2}]),
  +    UndecideableAtoms = [Name || {_, Name} <-(lists:usort(R1) -- lists:usort(R2))],
  +    ?debug("UndecidableAtoms:\n~p\n", [UndecideableAtoms]),
  +    ordsets:union(S1, ordsets:from_list(UndecideableAtoms)).   
  +
       
   reverse_module_graph(List) ->
       reverse_module_graph_1(List,List, []).
  
positive.code: 
  analyze_all_files([{Mod, Dir}|Left], SearchPaths) ->  
      FileName = filename:join(Dir,Mod++".erl"),
      FileModifiedTime = filelib:last_modified(FileName),
      R = ets:lookup(?ModuleGraphTab, {Mod, Dir}),
      case R of
  
negative.code: %% Author contact: hl@kent.ac.uk, sjt@kent.ac.uk
  %%======================================================================
  
  -module(refac_module_graph). 
  -export([module_graph/1, collect_called_modules/1]). 
  
  
  %%-define(DEBUG, true).
  
  -ifdef(DEBUG).
  -define(debug(__String, __Args), ?wrangler_io(__String, __Args)).
  -else.
  -define(debug(__String, __Args), ok).
  -endif.
  
  -include("../include/wrangler.hrl").
  
  -spec(module_graph/1::([dir()]) -> [{filename(), [filename()]}]).
  module_graph(SearchPaths) ->
      Files = refac_util:expand_files(SearchPaths, ".erl"),
      ?debug("Files:\n~p\n", [Files]),
      ModMap = refac_util:get_modules_by_file(Files),
      analyze_all_files(ModMap, SearchPaths).
     
  