clean up validation code to improve readability