wrote better validation code