use a safer memoize implementation