Changes from the v3.1.x branch

This brings in the changes from #3082.

Fixes #3080.  Fixes #3081.