Refactor uniqueness validation