Added while loop to code