anchor.diff:  group_by([]) -> [];
   group_by(SortedList=[{_Seq, Tok}|_T]) -> 
       {Es1, Es2} =lists:splitwith(fun({_S,T})-> rm_loc_in_tok(T) == rm_loc_in_tok(Tok) end, SortedList),
  -    [Es1 | group_by(Es2)]. 
  +    [Es1 | group_by(Es2)].
       
   
   get_sub_cs(_ZippedToks, [], Acc) -> Acc;
  
positive.code: %% @spec duplicated_code(FileName::filename(),MinLines::integer(),MinClones::integer()) -> term().
  %%  
  -spec(duplicated_code/3::([dir()], string(), string()) ->{ok, string()}).
  duplicated_code(DirFileList, MinLength1, MinClones1) ->
      io:format("\nCMD: ~p:duplicated_code(~p,~p,~p).\n", [?MODULE, DirFileList, MinLength1, MinClones1]),
      FileNames = refac_util:expand_files(DirFileList, ".erl"),
      %%io:format("FileNames:\n~p\n", [FileNames]),
      MinLength = case MinLength1==[] orelse  (list_to_integer(MinLength1)< ?DEFAULT_MIN_CLONE_LEN) of 
  		    true -> ?DEFAULT_MIN_CLONE_LEN;
  		    _ -> list_to_integer(MinLength1)
  		end,
       MinClones = case MinClones1==[] orelse (list_to_integer(MinClones1) <?DEFAULT_MIN_CLONE_MEMBER) of 
  		     true ->?DEFAULT_MIN_CLONE_MEMBER;
  		     _ -> list_to_integer(MinClones1)
  		 end,
      %% tokenize Erlang source files and concat them into a single list.
      {Toks, ProcessedToks} = tokenize(FileNames),
      %%io:format("Suffix Tree construction\n"),
      Tree = suffix_tree(alphabet()++"&",ProcessedToks++"&"),  %% '&' does not occur in program source.
      %%Clone collection from the suffix tree.
      %%io:format("Clone collection\n"),
      Cs=lists:flatten(lists:map(fun(B) -> collect_clones(MinLength,MinClones,B) end, Tree)),
       %% filter out sub-clones.
      %%io:format("Filter out sub clones\n"),
      Cs1 = filter_out_sub_clones(Cs),
     %% io:format("CloneNumbers:\n~p\n", [length(Cs1)]),
      %% put atom names back into the token streams, and get the new clones.
     %% io:format("put atoms back\n"),
      Cs2 = clones_with_atoms(Cs1, Toks, MinLength, MinClones),
     %% io:format("Cs2:\n~p\n", [Cs2]),
     %% io:format("Filter out sub clones\n"),
      Cs3 = filter_out_sub_clones(Cs2),
      %% combine clones which are next to each other. (ideally a fixpoint should be reached).
     %% io:format("Combine with neighbours\n"),
      Cs4 = combine_neighbour_clones(Cs3, MinLength, MinClones),
      %% Trim both ends of the clones to remove those parts that does not form a meaningful syntax phrases.
     %% io:format("Before Trimming:\n~p\n", [length(Cs4)]),
     %%  io:format("Trim clones\n"),
       %%io:format("Before trimming \n"),
       %%io:format("Cs5:\n~p\n", [Cs4]),
       Cs5 = trim_clones(FileNames, Cs4, MinLength, MinClones),
       Cs6 = remove_sub_clones(Cs5),
       case length(FileNames) of 
    	  1 ->  display_clones(Cs6);
    	 _ -> display_clones1(Cs6)
         end,
      %%io:format("Final clones:\n~p\n", [length(Cs6)]),
      {ok, "Duplicated code detection finished."}.
     
  -spec(duplicated_code_1/3::(dir(), [integer()], [integer()]) ->
  	     [{[{{filename(), integer(), integer()},{filename(), integer(), integer()}}], integer(), integer()}]).	     
  duplicated_code_1(DirFileList, MinLength1, MinClones1) ->
      FileNames = refac_util:expand_files(DirFileList, ".erl"),
      MinLength = case MinLength1==[] orelse  (list_to_integer(MinLength1)< ?DEFAULT_MIN_CLONE_LEN) of 
  		    true -> ?DEFAULT_MIN_CLONE_LEN;
  		    _ -> list_to_integer(MinLength1)
  		end,
      MinClones = case MinClones1==[] orelse (list_to_integer(MinClones1) <?DEFAULT_MIN_CLONE_MEMBER) of 
  		     true ->?DEFAULT_MIN_CLONE_MEMBER;
  		     _ -> list_to_integer(MinClones1)
  		 end,
      {Toks, ProcessedToks} = tokenize(FileNames),
      Tree = suffix_tree(alphabet()++"&",ProcessedToks++"&"),  %% '&' does not occur in program source.
      Cs=lists:flatten(lists:map(fun(B) -> collect_clones(MinLength,MinClones,B) end, Tree)),
      Cs1 = filter_out_sub_clones(Cs),
      Cs2 = clones_with_atoms(Cs1, Toks, MinLength, MinClones),
      %% io:format("Cs2:\n~p\n", [Cs2]),
      Cs3 = filter_out_sub_clones(Cs2),
      Cs4 = combine_neighbour_clones(Cs3, MinLength, MinClones),
      Cs5 = trim_clones(FileNames, Cs4, MinLength, MinClones),
      remove_sub_clones(Cs5).
   
  
  %% =====================================================================
  %% tokennization of an Erlang file.
  
  
negative.code: 	      filter_out_sub_clones_1(Cs, Acc1, ExistingRanges++Range)   
     end.
  
  sub_range({Range1, Len1, F1}, {Range2, Len2, F2}) ->
      case F1 =< F2 andalso Len1 =< Len2 of
        true ->
  	  lists:all(fun ({S, E}) -> lists:any(fun ({S1, E1}) -> S1 =< S andalso E =< E1 end, Range2) end, Range1);
        false -> false
      end.
  
  %% ==================================================================================
  %% This phase brings back those atoms back into the token stream, and get the resulted clones.
  