fixed some peculiarities of writing matrices and cubes