Begin of matrix implementation.