Backported fix for #763