cmem: proper handling of 2d- and 3d- arrays