Get matrix inversion working and fix determinant calculation.