General fixes

Hi Chris,

Here are a few fixes, manly adding configurable features. There are details in commit messages if needed. Apart from pep8 the individual commits could be cherry-picked.

Simon