Re-merge of 4b64d8342d The commit after this one contains the fix for the issue that led to the revert.
4b64d8342d