deconstructing the while loop into add node