[IMP]added sorting function