Separate out main
Minor refactoring