backport for #3774