completed implementation of memoized matrix inversion