Fixed bugs with missing root pointers, and added some debug functions to print ptrees.
Minor optomization.
Now using ptree in some situations.