Added functionality for caching matrix inverse