refactored a bit, added grouping to search results