Backported fix for #909