Enter/exit code sets up/tears down the thread's tree. Fixed a few spotted bugs in allocation and tree code.