Tail recursive version of factorial function