corrected validation code