Added matrix inverse caching function