Improve code health

Lots of little changes that shouldn't alter the way the code works (though the change to the logging commands might reduce overhead for messages that aren't logged).

- Change triple quoted comments to plain comments.
- Change string formatting to use arguments instead in the logging commands.
- Unpack tuples when passed to logging functions as they should just be a
  series of arguments.
- Comment out one unused import.
- Remove other unused imports.
- Rename format variable as it clashes with built-in.
- Tidy some white space.
- Correct `not x is y` tests to `x is not y`.
- Sort out some ambiguous indentation.
- Compact some long lines.
- Correct comparisons to None from `== None` to `is None`