Backport of #5526
Backport of #5526