Seperated search loop to be reusable