Memoization reworked