Refactor MatrixClass