added logic of what to do, built in memoization