Fix pyflakes and pep8 warnings