modified while loop