more fixes to the matrix function