Backport update and fix from trunk.