pep8, flakes, readability improvements

* remove unused imports
* shorten lines
* minor readability improvements on some conditionals