Refactoring main to make it a little cleaner