factorial in a tail recursive manner