Fixed the issue with group by and aggregations