Fixes a bug I just introduced, by fixing a bug.

I forgot that the inner scope isn't necessarily exited when updating
upperWasValid. (Additional iterations overwrote the result before the
upper level could read it.) This is fixed now. Inner level only adds to
the value, upper level resets it to 0 before going down.