Added matrix inversion caching