use while loop instead