General code cleanup in the direction of PEP-8

A lot of pep8 errors have been fixed, but a few requiring more in-depth
refactoring remain.