Functions changed to calculate matrix inversion.