Refactor balanced binary tree