updated while loop