copy the thought from previous removeDuplicates.