updated code to use quantiles