optimize duplicates check
eliminate redundant checks