added necessary matrix inverse caching code