Introduced logic for computing and caching the inverse of a matrix