Adjusted the while loop