Optimized duplicate removal.
Further optimization