This solution is not good, because services must be defined in correct order. When you move 'child' to last position, child, subchild and secchild will have depth = 1. And we are not certain that sort() preserves original order.