Added javascript sort function