Fix flake8 & bugs