Added tests and fix flake8