anchor.diff:  		      end
   		end
   	  end;
  -      tuple -> do_rename_fun_in_tuples(Node, {FileName, SearchPaths, ModName, FunName, TargetModName, Arity, Pid, TabWidth});
  -      _ -> {Node, false}
  -    end.
  -  
  +	tuple -> do_rename_fun_in_tuples(Node, {FileName, SearchPaths, MFAs, TargetModName, Pid, TabWidth});
  +	_ -> {Node, false}
  +    end.
  +
  +rename_in_qualified_app(Operator1, FunName1, Arguments1, TargetModName1) ->
  +    Operator2 = copy_pos_attrs(Operator1, 
  +			       refac_syntax:module_qualifier(refac_syntax:atom(TargetModName1),
  +							     refac_syntax:atom(FunName1))),
  +    refac_syntax:application(Operator2, Arguments1).
  +
   
   %% ====================================================================================
   %%  Processing Client modules.
   %%====================================================================================
   
  -refactor_in_client_modules(ClientFiles,{ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid) ->
  -    case ClientFiles of 
  -	[] -> [];
  -	[F | Fs] ->
  -	    ?wrangler_io("The current file under refactoring is:\n~p\n", [F]),
  -	    {ok, {AnnAST, Info}} =refac_util:parse_annotate_file(F,true, SearchPaths, TabWidth),     
  -	    {AnnAST1, Changed} = refactor_in_client_module_1(F, {AnnAST, Info}, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid),
  -	    check_atoms(F, AnnAST1, [FunName], Pid),
  -	    if Changed ->
  -		    [{{F,F}, AnnAST1} | refactor_in_client_modules(Fs, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid)];
  -	       true -> refactor_in_client_modules(Fs, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid)
  -	    end
  -    end.
  -refactor_in_client_module_1(FileName,{AnnAST, _Info}, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth,Pid) ->
  +refactor_in_client_modules(ClientFiles, MFAs, TargetModName, SearchPaths, TabWidth, Pid) ->
  +    case ClientFiles of
  +      [] -> [];
  +      [F| Fs] ->
  +	  ?wrangler_io("The current file under refactoring is:\n~p\n", [F]),
  +	  {ok, {AnnAST, Info}} = refac_util:parse_annotate_file(F, true, SearchPaths, TabWidth),
  +	  {AnnAST1, Changed} = refactor_in_client_module_1(F, {AnnAST, Info}, MFAs, TargetModName, SearchPaths, TabWidth, Pid),
  +	  AtomsToCheck = lists:usort([FunName || {_M, FunName, _A} <- MFAs]),
  +	  check_atoms(F, AnnAST1, AtomsToCheck, Pid),
  +	  if Changed ->
  +		 [{{F, F}, AnnAST1}| refactor_in_client_modules(Fs, MFAs, TargetModName, SearchPaths, TabWidth, Pid)];
  +	     true -> refactor_in_client_modules(Fs, MFAs, TargetModName, SearchPaths, TabWidth, Pid)
  +	  end
  +    end.
  +refactor_in_client_module_1(FileName,{AnnAST, _Info}, MFAs, TargetModName, SearchPaths, TabWidth,Pid) ->
       Forms  = refac_syntax:form_list_elements(AnnAST),
  -    {Forms1, C} = lists:unzip([process_in_client_module(FileName, Form, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid)||Form <-Forms]),
  +    {Forms1, C} = lists:unzip([process_in_client_module(FileName, Form, MFAs, TargetModName, SearchPaths, TabWidth, Pid)||Form <-Forms]),
       Forms2 = lists:append(Forms1),
       {copy_pos_attrs(AnnAST, refac_syntax:form_list(Forms2)), lists:member(true, C)}.
   
  -process_in_client_module(FileName, Form, {ModName, FunName, Arity}, TargetModName,SearchPaths, TabWidth, Pid) ->
  -     NewImport = refac_syntax:attribute(refac_syntax:atom('import'),
  -					[refac_syntax:atom(TargetModName),
  -					 refac_syntax:list([refac_syntax:arity_qualifier(refac_syntax:atom(FunName),
  -								       refac_syntax:integer(Arity))])]),
  +process_in_client_module(FileName, Form, MFAs = [{ModName, _, _}| _T], TargetModName, SearchPaths, TabWidth, Pid) ->
       case refac_syntax:type(Form) of
  -	function -> {Form1, C} =change_module_qualifier(FileName, Form, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid),
  -		    {[Form1], C};
  -	attribute -> Name = refac_syntax:attribute_name(Form),
  -		     case refac_syntax:type(Name) of
  -			 atom -> case refac_syntax:atom_value(Name) of
  -				     import ->
  -					 case refac_syntax:attribute_arguments(Form) of 
  -					     [H, L] ->
  -						 case refac_syntax:atom_value(H) of 
  -						     ModName ->
  -							 Es = refac_syntax:list_elements(L),
  -							 Es1 = [E || E <- Es,
  -								     {refac_syntax:atom_value(refac_syntax:arity_qualifier_body(E)),
  -								      refac_syntax:integer_value(refac_syntax:arity_qualifier_argument(E))}
  -									 =/= {FunName, Arity}],
  -							 case length(Es1) of 
  -							     0 ->
  -								 {[NewImport], true};
  -							     _ -> case length(Es) == length(Es1) of 
  -								      true -> {[Form], false};
  -								      _ ->
  -									  {[copy_pos_attrs(Form, refac_syntax:attribute(Name, [H, refac_syntax:list(Es1)])),
  -									    NewImport],true}
  -								  end
  -							 end;
  -						     _ -> {[Form], false}
  -						 end;
  -					     _ -> {[Form], false}
  -					 end;
  -				     _ -> {[Form], false}
  -				 end;
  -			 _ -> {[Form], false}
  -		     end;
  -	_ -> {[Form], false}
  -    end.
  -
  -
  -change_module_qualifier(FileName, Form, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid) ->
  +      function ->
  +	  {Form1, C} = change_module_qualifier(Form, FileName,MFAs, TargetModName, SearchPaths, TabWidth, Pid),
  +	  {[Form1], C};
  +      attribute ->
  +	  Name = refac_syntax:attribute_name(Form),
  +	  case refac_syntax:type(Name) of
  +	    atom -> case refac_syntax:atom_value(Name) of
  +		      import ->
  +			  case refac_syntax:attribute_arguments(Form) of
  +			    [H, L] ->
  +				case refac_syntax:atom_value(H) of
  +				  ModName ->
  +				      Es = refac_syntax:list_elements(L),
  +				      Es1 = [E || E <- Es,
  +						  F1 <- [refac_syntax:atom_value(refac_syntax:arity_qualifier_body(E))],
  +						  A1 <- [refac_syntax:integer_value(refac_syntax:arity_qualifier_argument(E))],
  +						  not lists:member({ModName, F1, A1}, MFAs)],
  +				      Es2 = Es -- Es1,
  +				      case length(Es1) == length(Es) of
  +					true ->
  +					    {[Form], false};
  +					false ->
  +					    Imp1 = copy_pos_attrs(Form, refac_syntax:attribute(
  +									  Name, [H, refac_syntax:list(Es1)])),
  +					    Imp2 = refac_syntax:attribute(refac_syntax:atom(import),
  +									  [refac_syntax:atom(TargetModName),
  +									   refac_syntax:list(Es2)]),
  +					    {[Imp1, Imp2], true}
  +				      end;
  +				  _ -> {[Form], false}
  +				end;
  +			    _ -> {[Form], false}
  +			  end;
  +		      _ -> {[Form], false}
  +		    end;
  +	    _ -> {[Form], false}
  +	  end;
  +      _ -> {[Form], false}
  +    end.
  +
  +
  +change_module_qualifier(Form, FileName, MFAs, TargetModName, SearchPaths, TabWidth, Pid) ->
       ast_traverse_api:full_tdTP(fun do_change_module_qualifier/2,
  -			       Form, {FileName, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid}).
  -
  -do_change_module_qualifier(Node, {FileName, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid}) ->
  -    MakeApp = fun (Node1, Operator1, Arguments1, TargetModName1, FunName1) ->
  -		      Operator2 = copy_pos_attrs(Operator1, refac_syntax:module_qualifier(refac_syntax:atom(TargetModName1),
  -											  refac_syntax:atom(FunName1))),
  -		      Node2 = copy_pos_attrs(Node1, refac_syntax:application(Operator2, Arguments1)),
  -		      {Node2, true}
  -	      end,
  +			       Form, {FileName, MFAs, TargetModName, SearchPaths, TabWidth, Pid}).
  +
  +do_change_module_qualifier(Node, {FileName, MFAs, TargetModName, SearchPaths, TabWidth, Pid}) ->
       case refac_syntax:type(Node) of
  -      application ->
  -	  Op = refac_syntax:application_operator(Node),
  -	  Args = refac_syntax:application_arguments(Node),
  -	  case lists:keysearch(fun_def, 1, refac_syntax:get_ann(Op)) of
  -	    {value, {fun_def, {Mod1, Fun1, Ari1, _, _}}} ->
  -		case lists:keysearch({Mod1, Fun1, Ari1}, 1, refac_misc:apply_style_funs()) of
  -		  {value, _} ->
  -		      transform_apply_style_calls(FileName, Node, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth);
  -		  false ->
  -		      case {Mod1, Fun1, Ari1} of
  -			{ModName, FunName, Arity} ->
  -			    case refac_syntax:type(Op) of
  -			      module_qualifier ->
  -				  MakeApp(Node, Op, Args, TargetModName, FunName);
  -			      tuple -> {rename_fun_in_tuple_op(Node, Op, Args, TargetModName), true};
  -			      _ -> {Node, false}
  -			    end;
  -			_ -> {Node, false}
  -		      end
  -		end;
  -	    _ -> {Node, false}
  -	  end;
  -      implicit_fun -> process_implicit_fun(Node, ModName, FunName, Arity, TargetModName);
  -      tuple -> do_rename_fun_in_tuples(Node, {FileName, SearchPaths, ModName,
  -					      FunName, TargetModName, Arity, Pid, TabWidth});
  -      _ -> {Node, false}
  +	application ->
  +	    Op = refac_syntax:application_operator(Node),
  +	    Args = refac_syntax:application_arguments(Node),
  +	    case lists:keysearch(fun_def, 1, refac_syntax:get_ann(Op)) of
  +		{value, {fun_def, {Mod1, Fun1, Ari1, _, _}}} ->
  +		    case lists:keysearch({Mod1, Fun1, Ari1}, 1, refac_misc:apply_style_funs()) of
  +			{value, _} ->
  +			    transform_apply_style_calls(FileName, Node, MFAs, TargetModName, SearchPaths, TabWidth);
  +			false ->
  +			    case lists:member({Mod1, Fun1, Ari1}, MFAs) of
  +				true ->
  +				    case refac_syntax:type(Op) of
  +					module_qualifier ->
  +					    Node2=copy_pos_attrs(Node, rename_in_qualified_app(Op, Fun1, Args, TargetModName)),
  +					    {Node2, true};								
  +					tuple -> {rename_fun_in_tuple_op(Node, Op, Args, TargetModName), true};
  +					_ -> {Node, false}
  +				    end;
  +				false ->
  +				    {Node, false}
  +			    end
  +		    end;
  +		_ -> {Node, false}
  +	    end;
  +	implicit_fun -> process_implicit_fun(Node, MFAs, TargetModName);
  +	tuple -> do_rename_fun_in_tuples(Node, {FileName, SearchPaths, MFAs,
  +						TargetModName,Pid, TabWidth});
  +	_ -> {Node, false}
       end.
   
   rename_fun_in_tuple_op(App,Op, Args, TargetModName) ->
  
positive.code:     Op1 = copy_pos_attrs(Op, refac_syntax:tuple([copy_pos_attrs(M, refac_syntax:atom(TargetModName)), F])),
      copy_pos_attrs(App, refac_syntax:application(Op1, Args)).
      
    
  %%================================================================================
  %%              Some Utility Functions 
  %%================================================================================
  
  make_export(Names) ->
      Es = [refac_syntax:arity_qualifier(refac_syntax:atom(F),refac_syntax:integer(A))
  	  || {F, A} <- Names],
      [refac_syntax:attribute(refac_syntax:atom('export'), [refac_syntax:list(Es)])].
  
  copy_pos_attrs(E1, E2) ->
      refac_syntax:copy_pos(E1, refac_syntax:copy_attrs(E1, E2)).    
  
      
  is_attribute(F, Name) ->
      refac_syntax:type(F) == attribute andalso
        refac_syntax:type(refac_syntax:attribute_name(F)) == atom andalso
  	refac_syntax:atom_value(refac_syntax:attribute_name(F)) == Name.
         
  %% =====================================================================
  %% @spec application_info(Tree::syntaxTree())->term()
  %% ====================================================================       
  application_info(Node) ->
      case refac_syntax:type(Node) of 
  
negative.code:      "module name within the following expressions while without enough "
       "syntactic/semantic information.\n Please check manually!\n".
    
  not_renamed_warn_msg(FunNames) ->
      "\n=================================================================================\n"
       "WARNING: Wrangler could not infer whether the uses of '" ++format_names(FunNames) ++"' at the following positions "
       "refer to the function moved.\n Please check manually for necessary module name changes!\n".
  format(Format, Options) ->
      lists:flatten(io_lib:format(Format, Options)).
  
  get_module_name(ModInfo) ->
      case lists:keysearch(module, 1, ModInfo) of
        {value, {module, ModName}} -> ModName;
        false -> throw({error, "Wrangler could not infer the current module name."})
      end.
  