switched to while loop