Made some improvements to the validation code