Fixed bugs in submatrix