Refactored the executeSearch command into two methods