Fixed flake8 errors and warnings