Split up the iterative search procedure.

This leaves some unimplemented details in there, but in the overall setting,
I like this better.