refactor binary tree