Topic/cleanup

Lots of cleanup, mostly formatting to conform to pep8 standards better, some DRYing out of the code.  Issues that haven't been fixed here have been logged as separate issues.