added memoization but doesn't seem to be working - debugging