changed sort function