Fix flake8 and other mistakes