Be a bit more pythonic, replace some depricated usages.

Lots of PEP8 fixes.

Mostly what is left to be cleaned up here is indent and
line length issues.