Changed the matrix functions