Added an if to detect if there is nothing more to search.