Fix python3 compatibility and pep8