Fixed several bugs in matrix class. Added new test cases to MatrixTest.