Fixed some Python3 and flake8 errors