Code cleanup #3064: reorganize imports, other minor pep8 fixes

Just a little warm-up. I also fixed some other issues like empty lines with spaces because imports where not so bad in this case.