Minor performance optimisation. Getting submatrix one time

instead of getting it on each iteration