anchor.diff:  	end,
       Es = refac_syntax_lib:fold(F, [], Tree),
       [E ||  E <- Es, length(E) >= MinLen].
  -		 
  -
  -
  -      
  -
  -%% get the binding structure of variables.
  +
  +
  +%% Get the binding structure of variables.
   %%-spec(var_binding_structure/1::([syntaxTree()]) -> [{integer(), integer()}]).      
  +
   var_binding_structure(ASTList) ->
  -    Fun1 = fun (T, S) ->
  -		   case refac_syntax:type(T) of
  -		     variable ->
  -			 Name = refac_syntax:variable_name(T),
  -			 SrcLoc = refac_syntax:get_pos(T),
  -			 As = refac_syntax:get_ann(T),
  -			 case lists:keysearch(def, 1, As) of
  -			   {value, {def, DefLoc}} ->
  -			        [{atom_to_list(Name), SrcLoc,
  -						    DefLoc}|S];
  -			   _ -> S
  -			 end;
  -		     _ -> S
  -		   end
  -	   end,
  -    %% collect all variables including their defining and occuring locations. 
  -    B = lists:keysort(2, lists:flatmap(fun(T) -> refac_syntax_lib:fold(Fun1, [], T) end, ASTList)),
  -    %% collect occuring locations.
  -    SrcLocs = lists:map(fun ({_Name, SrcLoc, _DefLoc}) -> SrcLoc end, B),
  -    Res = case SrcLocs of 
  -	      [] -> 
  -		  [];
  -	      _ ->  IndexedLocs = lists:zip(SrcLocs, lists:seq(1, length(SrcLocs))),
  -		    B1 = lists:usort(lists:map(fun ({_Name, SrcLoc, DefLoc}) ->
  -						       DefLoc1 = hd(DefLoc),             %% DefLoc is  a list, does this cause problems? .
  -						       {value, {SrcLoc, Index1}} = lists:keysearch(SrcLoc, 1, IndexedLocs),
  -						       Index2 = case lists:keysearch(DefLoc1, 1, IndexedLocs) of 
  -								    {value, {_, Ind}} -> Ind;
  -								    _ -> 0 %% free variable
  -								end,
  -						       {Index1, Index2}
  -					       end,
  -					       B)),
  -		    lists:keysort(1, B1)
  +    VarLocs = lists:keysort(2, collect_vars(ASTList)),
  +    case VarLocs of
  +      [] ->
  +	  [];
  +      _ -> var_binding_structure_1(VarLocs)
  +    end.
  +
  +var_binding_structure_1(VarLocs) ->
  +    SrcLocs = [SrcLoc || {_Name, SrcLoc, _DefLoc} <- VarLocs],
  +    IndexedLocs = lists:zip(SrcLocs, lists:seq(1, length(SrcLocs))),
  +    Fun = fun ({_Name, SrcLoc, DefLoc}) ->
  +		  DefLoc1 = hd(DefLoc),
  +		  {value, {SrcLoc, Index1}} = lists:keysearch(SrcLoc, 1, IndexedLocs),
  +		  Index2 = case lists:keysearch(DefLoc1, 1, IndexedLocs) of
  +			       {value, {_, Ind}} -> Ind;
  +			       _ -> 0 %% free variable
  +			   end,
  +		  {Index1, Index2}
   	  end,
  -    Res.
  +    BS = [Fun(VL) || VL <- VarLocs],
  +    lists:keysort(1, lists:usort(BS)).
  +
  +collect_vars(AST) when is_list(AST) ->
  +    lists:flatmap(fun (T) -> collect_vars(T) end, AST);
  +collect_vars(AST) ->
  +    Fun = fun (T, S) ->
  +		  case refac_syntax:type(T) of
  +		    variable ->
  +			Name = refac_syntax:variable_name(T),
  +			SrcLoc = refac_syntax:get_pos(T),
  +			As = refac_syntax:get_ann(T),
  +			case lists:keysearch(def, 1, As) of
  +			  {value, {def, DefLoc}} ->
  +				[{atom_to_list(Name), SrcLoc, DefLoc}| S];
  +			    _ -> S
  +			end;
  +		      _ -> S
  +		  end
  +	  end,
  +    refac_syntax_lib:fold(Fun, [], AST).
  +
   
   compose_search_result_info(FileName, Ranges) ->
       compose_search_result_info(FileName, Ranges, "").
  
positive.code: 		    refac_syntax:default_literals_vars(Node, '%');
  		atom -> case lists:keysearch(fun_def,1,refac_syntax:get_ann(Node)) of 
  			    false ->refac_syntax:default_literals_vars(Node, '%') ;
  			    _ -> refac_syntax:default_literals_vars(Node, refac_syntax:atom_value(Node))
  			end;
  		nil -> refac_syntax:default_literals_vars(Node, nil);
  		underscore ->refac_syntax:default_literals_vars(Node, '&');
  
negative.code: 
  %% Search the clones of an expression from Tree.
  search_one_expr(Tree, Exp) ->
      SimplifiedExp = simplify_expr(Exp),
      BdStructExp = var_binding_structure([Exp]),
      F = fun (T, Acc) ->
  		case refac_util:is_expr(T) of
  		  true -> T1 = simplify_expr(T),
  			  case SimplifiedExp == T1 of
  			      true ->
  				  case var_binding_structure([T]) of
  				      BdStructExp ->
  					  StartEndLoc = refac_util:get_range(T),
  					  [StartEndLoc| Acc];
  				      _ -> Acc
  				  end;
  			      _ -> Acc
  			  end;
  		    _ -> Acc
  		end
  	end,
      lists:reverse(refac_syntax_lib:fold(F, [], Tree)).
      
  
  %% Search for the clones of an expresion sequence.
  search_expr_seq(Tree, ExpList) ->
      AllExpList = contained_exprs(Tree, length(ExpList)),
      lists:flatmap(fun(EL) ->get_clone(ExpList, EL) end, AllExpList).
     
  get_clone(ExpList1, ExpList2) ->
      Len1 = length(ExpList1),
      Len2 = length(ExpList2),
      case Len1 =< Len2 of
        true ->
  	  SimplifiedExpList1 = simplify_expr(ExpList1),
  	  SimplifiedExpList2 = simplify_expr(ExpList2),
  	  case lists:prefix(SimplifiedExpList1, SimplifiedExpList2) of
  	    true ->
  		  List22 = lists:sublist(ExpList2, Len1),
  		  BdList1 = var_binding_structure(ExpList1),
  		  BdList2 = var_binding_structure(List22),
  		  case BdList1 == BdList2 of
  		      true ->
  			  E1 = hd(List22),
  			  En = lists:last(List22),
  			  {StartLoc, _EndLoc} = refac_util:get_range(E1),
  			  {_StartLoc1, EndLoc1} = refac_util:get_range(En),
  			  [{StartLoc, EndLoc1}] ++ get_clone(ExpList1, tl(ExpList2));
  		      _ -> get_clone(ExpList1, tl(ExpList2))
  		  end;
  	      _ -> get_clone(ExpList1, tl(ExpList2))
  	  end;
  	_ -> []
      end.
  	    
  
  %% Simplify expressions by masking variable names, literals and locations.
  simplify_expr(Exp)when is_list(Exp) ->
      [simplify_expr(E)|| E<-Exp];
  simplify_expr(Exp) ->
      refac_util:full_buTP(
        fun(Node,_Others)->
  	      do_simplify_expr(Node) 
        end, Exp,{}).
  
  
  do_simplify_expr(Node) ->
      Node1 = case refac_syntax:type(Node) of 
  