reimplemented percentile algorithm