Extract caching and grouping to methods