https://stackoverflow.com/questions/1319903/how-to-flatten-a-multidimensional-array