Backported fix for #888