search refactor + tidy