Added code to cache inverse