add some tests and fix some issues with the matrix calculations