Backport fix for #975