finished btree, may have some code refinement