Add function unfold and memoization