Code cleanup.

 * PEP-8 compliance.
 * Proper python3 code all-round (some code portions were bound to fail).
 * Other minor cleanups and tinying up.