added some validation code