refactor calculateQuantile method