This isn't a functional change, but it makes our logic more clear, and catches bugs earlier.
Core of an implementation for 22976.