Wrote method for search function