Added functions to compute matrix inverse and cache it