fix merge (mostly remove duplicate functions in treelib)