Fix flake8 warnings and errors