fix for multidimensional matrices