matrix inv caching code and comments