changed while loop to while NOT x