Fix infinite loop on backtracking