improve the sort() function that runs when <th> is clicked