added matrix inversion function