Backport improvements from 2.3 branch