Move validate() function to the bottom