Refactored a lot of code out of Main