tail recursive factorial function