Updated getInverse function