Minor enhancements and refactoring of search and query.