wrote factorial function