Moved sorting into its own function to be used by Quartile and fixed an uncaught bug in Percentile