Set proper parent hierachy and remove duplicated tags from childs