updated functions for caching inverse