switching to while loop