Fix pep8 and pyflakes issues

This pull request fixes (all the) 2516 pep8 and pyflakes issues.