Improve performance of factorial function.  We now implement it in terms of previously calculated smaller factorials, which we cache.  Stack gets blown out at about 5000! so if that turns out to regularly be an issue we should replace the use of tail-recursion with something iterative.