Implementation of sorting function by the tag.