Ensure that the pages is not empty before using it (could be empty if search emptied it)
Reindent
Use grep for more speed