Changed while loop to Condition