Implementing cached inverse matrix