Cleanup

A bit of code cleanup, to move the main method into its own method.