Add function to calculate a factorial