recursive to memoization