Backport of a808873, "pull storm" fix, plus bug fix 9cfb818