fix groupby logic