Refactor some search stuff