Backport of #488
Backport of #488