making cmd_sort function