fix flake8 warnings

Mostly folding lines and fiddling with missing / superfluous spaces.
On a couple occastion, adding an intermediate variable or removing an
unused one.