adjust to a while loop