Functions for caching matrix invert