Refactor binary tree