Fix matrix inversion algorithm.