Moved search next match code to its own function.