functions for cached matrix inversion