made the auto search function as its own function