added matrix inverse caching function