implemented flattening of array of arrays