Add missing p1 parameter to percentile and threshold functions
Add specific branch for the percentile p0 = 0 case
Fix accidential variable naming confusion