Fix percentile calculation - partly wrong values, and sometimes warnings regarding array_flip