Trap infinite loop in remaining_occurrences