Added functions to calculate and cache matrix inverse.