Moved the common conversion functions out into its own file

This makes it easier to figure out what the hell is going on if you're trying
to use these tools for your own purposes.