Fix compatibility issues and flake8.