Refactoring build_feature_tree