Implement next node condition in reduce