Wrote matrix inversion functions