Refactor the third tree building step into classify_children().