I don't think a new function is needed here. there is already a recursive function building the terms, It is best if we can use that since some things will be missed if we have two separate functions.  ie. there is a call to usort in one but not the other.  Probably best to just separate out the theming component if possible.