added memoized form of factorial function