Fix a bug in remove duplicates function which caused extra tuples to be removed.