Cleanup: Move the utility code to its own file.