functioning version of matrix inversion cache