Modularized and refactored the search functions