Rebased #2696

supersedes #2696