Rebase region swap

Rebased from v1.80 as some other commits had got into the other PR somehow. #1076

Sorry for the multiple PR's