fix memoization related bug