added ability for pagination in queries with groups