Modified code to cache inverse of a matrix