updated for matrix inverse caching