fix obvious bugs found by pyflakes
removed dead code
make flake8 happy