Replacement for @raoulb pr#914

See #914

ToDo:
- [x] tests
- [x] final rebase
But I believe it is unecessary: see b65fc7dfd3e033cba9271f9406c68c980d3317f0