Groupby & aggregate function impl