Removing duplicates in batches