no recursive

change recursive to while loop to save stack