improve validation function

improve validation function