Added group by functionality