Implementation of inverse function