added confidence calculations and minConfidence loop