change to using while