Added memoization

Code paths that aren't TCE are memoized