Updated the code to perform matrix inversion