Move some helper functions into their own file.