move the utlity functions to a new file, and add a switch to stop on error