Corrected validation code