added code for stats by group