Added the generic tree traversal code.