adds proper working memoization code