Lots of pep8 cleanup
pep8 fixes. Indentation with 3 spaces is a bad idea.

Note on logging: logger.debug() already does its own variable replacement,
simply with %s (perhaps also with {}). No need to call .format.
Loads of pep8