issue #20212: Pull in some generally useful fixes and refactoring.

Don't pull this in until after the 1.3.4 tag.