implement cacheMatrix