Split lookup state out of the lookup function.

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