Fix sorting JS functionality