Fixed re-building tree each time.

Now keeps pointer to current state in tree. When moving the head,
parent and cousins are freed.