Check out some of my posts.
Tree copying, topological sorting, and a queue design that quietly removes a whole class of bugs.