Use groupBy and mapValues instead of foldLeft