collect and flat_map to return new arrays