MDL-61410 question: move tag sorting logic to a new function