Updated method groupBy and sortBy