Implemented cached matrix inverse