Add C-side clone_node callback
Fix tree building and add proper root document node