Backport #4224 to 3-2-stable.

This is a version of #4481 that makes the functional changes while attempting to be minimally invasive.