Correct regression in rescan logic.

The recent commit (27bd7b5a07f24a7b65c0c1df1f0461c4f9bab257) did not produce
incorrect results, but lead to more rescans than necessary (we neglected to
reset the needs-rescan flag at end-of-tick).