added a while loop