Refactored duplicate items logic