Fix validation logic. A simpler way and more readable solution.