Add groupBy func plus tests