group by functionality now working