Improve validation logic