Added factorial function