implemented inversion caching matrix functions