FREQUENCIES: Refactor and simplify percentiles calculations.