Correct exit condition of loop.