PEP 8/code readability changes

No changes to code behavior, only cosmetic changes to improve readability and PEP 8 compliance. Now passes flake8.