Simpler tail recursive implementation