Fix infinite loop in tuplet function