half of tree-construct code implemented