Replacement for @raoulb pr#914

See #914

ToDo:
- [x] tests
- [x] final rebase
Do we really test all rewrites from any to any other function?