added cached inverse matrix computation