bugfix: prev was always pointing to root. Now reset it to the last node
added to the tree