Flake8 fixes

Makes most of the code pass flake8 linting cleanly.