added Array.flatten to to handle multidimensional arrays