Fix remaining PEP8 and pyflakes issues, remove unused imports.