Modified code to inverse the matrix