refactored to accept any size matrix, created new tests, passed all tests