Fixed issues in matrix class