Use tail call in reduce