Backport for #379 in 2.3