updated code to cache inverse of matrix