A version of !799 (merged) for backporting to 3.34, leaving out the cleanups like renaming variables.