add memoization with UglyMemo