more merging with memoization