Stuff missing from previous backport.
Backport 1c0c24cb8f3940aca0.