Code cleanup

Figured I'd get a pull request going for this, to make it easier to keep track of what gets changed and when. Also makes it easier if anyone wants to jump in and make some changes or some suggestions.

Let's make this crappy python slightly less crappy!