Backport partial fix for #254