Split lookup state out of the lookup function.

This way multiple lookup scans can be performed while keeping the same data.
Self-review.

[#57443908]