added median sort. added helpers functions for median sort