Working version of cached matrix inversion