rbtree refactor