Fixed and extended the matrix classes