Converted a lot of the processing from the main loop into functions, as it should be. It's still not perfect, but it's much better.

I still want to add some better condintionals to the main loop, mostly because I don't want it to exit because a bad filename was given. Soon.