Updated Function to calucalate Inverse of Matrix