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.
Yes, for some reason this was set to descending order and then put through an array_reverse. Might as well do it all in one swell foop.