Write cacheMatrix function