Changed to checking in while loop