Fix bug in tag sorting