added inverse matrix caching