Prepare bugfix release 4.0.6.

Backports of the PRs  #694 and #693 to the `4.0-stable` branch, will be released as `4.0.6`.

@deiferni please have a look ...