Replacement for @raoulb pr#914

See #914

ToDo:
- [x] tests
- [x] final rebase
And do we really want to test all? It seems to be very tedious to do so.