replaced ismatrix with ndims to make it work for older versions