Fix incorrect comparisons in reduce functions