Added caching of computation of matrix inverse