anchor.diff:  	      File, Threshold, Tabs, ASTPid, true,SearchPaths, TabWidth)
       end.
   
  +%% Generalise and hash the AST for an single Erlang file.
   generalise_and_hash_file_ast_1(FName, Threshold, Tabs, ASTPid, IsNewFile, SearchPaths, TabWidth) ->
       {ok, {AnnAST, _Info}} = refac_util:quick_parse_annotate_file(FName, SearchPaths, TabWidth),
       Forms =refac_syntax:form_list_elements(AnnAST),
  -    lists:foreach(fun (Form) -> 
  -			  case refac_syntax:type(Form) of 
  -			      function ->
  -				  generalise_and_hash_function_ast(Form, FName, IsNewFile, Threshold, Tabs, ASTPid);
  -			      _ -> ok
  -			  end
  -		  end, Forms).
  -
  +    F =fun (Form) -> 
  +	       case refac_syntax:type(Form) of 
  +		   function ->
  +		       %% only process function definitions.
  +		       generalise_and_hash_function_ast(Form, FName, IsNewFile, Threshold, Tabs, ASTPid);
  +		   _ -> ok
  +	       end
  +       end,
  +    lists:foreach(fun(Form) -> F(Form) end, Forms).
  +
  +%% generalise and hash the AST of a single function.
   generalise_and_hash_function_ast(Form, FName, IsNewFile, Threshold, Tabs, ASTPid) ->
       FunName = refac_syntax:atom_value(refac_syntax:function_name(Form)),
       Arity = refac_syntax:function_arity(Form),
       HashVal = erlang:md5(refac_prettypr:format(Form)),
       case IsNewFile of
  -      true ->
  +	true ->
   	  %% a new file;
  -	  generalise_and_hash_function_ast_1(FName, Form, FunName, Arity, HashVal, Threshold, Tabs, ASTPid);
  -      false ->
  -	  %% a chnanged file;
  -	  case ets:lookup(Tabs#tabs.var_tab, {FName, FunName, Arity}) of
  -	    [{{FName, FunName, Arity}, HashVal, _VarInfo}] ->
  -		%% this function has not been syntactically changed, but location might be changed.
  -		{StartLine, _} = refac_syntax:get_pos(Form),
  -		quick_hash_function(ASTPid, {{FName, FunName, Arity}, StartLine});
  -	    _ ->
  -		%% A new function,
  -		generalise_and_hash_function_ast_1(FName, Form, FunName, Arity, HashVal, Threshold, Tabs, ASTPid)
  -	  end
  -    end.
  -
  +	    generalise_and_hash_function_ast_1(FName, Form, FunName, Arity, HashVal, Threshold, Tabs, ASTPid);
  +	false ->
  +	    %% a chnanged file;
  +	    case ets:lookup(Tabs#tabs.var_tab, {FName, FunName, Arity}) of
  +		[{{FName, FunName, Arity}, HashVal, _VarInfo}] ->
  +		    %% Same Hash value means that this function has not be
  +		    %% syntactically changed, but location might be changed.
  +		    %% StartLine is used to get the absolute location of the function.
  +		    {StartLine, _} = refac_syntax:get_pos(Form),
  +		    quick_hash_function(ASTPid, {{FName, FunName, Arity}, StartLine});
  +		_ ->
  +		    %% Function is new, or has been edited since last run of clone detection.
  +		    generalise_and_hash_function_ast_1(FName, Form, FunName, Arity, HashVal, Threshold, Tabs, ASTPid)
  +	    end
  +    end.
  +%% generalise and hash a function that is either new or has been changed since last run of clone detection.
   generalise_and_hash_function_ast_1(FName, Form, FunName, Arity, HashVal, Threshold, Tabs, ASTPid) ->
       {StartLine, _} = refac_syntax:get_pos(Form),
  -    {Form1, _} = ast_traverse_api:full_tdTP(fun do_abs_to_relative_loc/2, Form, StartLine),
  +    %% Turn absolute locations to relative locations, so 
  +    %% so that the result can be reused.
  +    Form1 = absolute_to_relative_loc(Form, StartLine),
       %% all locations are relative locations.
  +    %% variable binding information is needed by the anti-unification process.
       AllVars = refac_misc:collect_var_source_def_pos_info(Form1),
       %% I also put the Hashvalue of a function in var_tab.
       ets:insert(Tabs#tabs.var_tab, {{FName, FunName, Arity}, HashVal, AllVars}),
       ast_traverse_api:full_tdTP(fun generalise_and_hash_function_ast_2/2,
   			       Form1, {FName, FunName, Arity, ASTPid, Threshold, StartLine}).
   
  +%% generalise and has the function AST.
   generalise_and_hash_function_ast_2(Node, {FName, FunName, Arity, ASTPid, Threshold, StartLine}) ->
       F = fun (Body) ->
   		case length(Body) >= Threshold#threshold.min_len of
   		    true ->
  -			%% only store those expression sequences whose length is 
  -			%% greater than the threshold specified.
  +			%% only store those expression sequences whose  
  +			%% length is greater than the threshold specified.
   			insert_to_ast_tab(ASTPid, {{FName, FunName, Arity}, Body, StartLine});
   		    false ->
   			ok
  
positive.code:     DefinePos.
  
  
  get_anti_unifier(TmpASTTab, {ExprKeys, SubSt, ExportVars}) ->
      Exprs1 = [ExpAST || {ExprKey, _,_,_} <- ExprKeys, {_Key, ExpAST} <- ets:lookup(TmpASTTab, ExprKey)],
      %%refac_io:format("ExportVars:\n~p\n", [ExportVars]),
      refac_prettypr:format(anti_unification:generate_anti_unifier(Exprs1, SubSt, ExportVars)).
  
  
     
  get_clone_member_start_end_loc(Range)->
      {{File, _, _, _}, _Toks, {{{Line1, Col1},_},StartLine},_} = hd(Range),
      {_ExprKey1, _Toks1,{{_, {Line2, Col2}}, StartLine},_}= lists:last(Range),
      {{File, Line1+StartLine-1, Col1}, {File, Line2+StartLine-1, Col2}}.
    
  get_clone_class_in_absolute_locs({Ranges, {Len, Freq}, AntiUnifier}) ->
       StartEndLocs = [get_clone_member_start_end_loc(R) || R <- Ranges],
      {Ranges, {Len, Freq}, AntiUnifier,StartEndLocs}.
  
  get_expr_list(ExprKeys=[{{_FName, _FunName, _Arity, _Index}, _Toks, {_StartEndLoc, _StartLine}, _IsNew}|_T], ASTTab)->
      [ExpAST||{ExprKey,_,_,_}<-ExprKeys, {_Key, ExpAST}<-ets:lookup(ASTTab, ExprKey)].
   
  
  get_vars_to_export(Es, {FName, FunName, Arity}, VarTab) ->
      AllVars = ets:lookup(VarTab, {FName, FunName, Arity}),
      %%refac_io:format("AllVars:\n~p\n", [AllVars]),
      {_, EndLoc} = refac_misc:get_start_end_loc(lists:last(Es)),
      %%refac_io:format("\nEndLoc:\n~p\n", [EndLoc]),
        case AllVars of
  	  [] -> [];
  	  [{_, _, Vars}] ->
  	      ExprBdVarsPos = [Pos || {_Var, Pos} <- refac_misc:get_bound_vars(Es)],
  
negative.code:     F = fun ({Elem, I}) ->
  		lists:duplicate(length(F0(I)), {I, Elem})
  	end,
      IndexStr = lists:append([F0(I) || {_, I} <- Data]),
      SuffixTreeExec = filename:join(?WRANGLER_DIR, "bin/suffixtree"),
      Cs = suffix_tree:get_clones_by_suffix_tree(Dir, IndexStr ++ "&", MinLen, 
  