Refactored some code out of Main.cs