Added a memoize function