Fixup misc flake8 errors and problems

Probably resolves some minor bugs as well.