fix multidimensional matrices