Added a factorial function