Stability improvement

This is a copy of #7625, to be rebuilt with new CI.