Clean up infinite for loops in line search