implemented 'groupBy' function