Created chached matrix inversion function