added proper group by