finished backend code for group stats