Backport 72c958df6.
Backport 4c947f188dd2.
Backport 7b172ac6d7737f019.