Pep8tified, apart from E501 violations (line too long)
Miscellaneous fixes recommended by Rail in his review