added validate() function