Simplifying memoization logic