Fix error in removing duplicates.