some code in EliminateDuplicates and 2 new functions