added logic for confidence intervals