Improvements to matrix and its test