Nested grouping of arrays