changed sort to numeric sort for median calculation