Fix how matches are tracked

Instead of keeping track of the page index that we start
a search from, just keep track of the total number of pages
and make sure we don't visit pages more than once.