PyCharm-based fixing/cleaning

The PyCharm IDE offers advanced code inspection. This pull-request brings (mostly stylistic) changes suggested by the tool, as well as a handful of potential bug fixes.

Many more could be investigated.