Rebasing #3518

This is just a rebase of #3518 against the 2.3 branch so that it can be merged cleanly.