refactor category search logic