Move utility functions to end; move validate() to top