Fix Flake8 errors and warnings

I didn't check the code for full compliance to the style guide yet, but this should fix the build.