Some fixes and unused imports removed, thanks to pyflakes