make flattenTree sort recursive