matrix: bunch of fixes for matrix operations