Merge some work by @riccardobevilacqua (Thanks a lot!).