Refactor Main Source File

Just a quick clean up, removing some redundancies and extracting concerns into their own methods. Still more can be done, but this is a start.
Is this an integer then still? It's possible the type casting matters here...not sure though.