added logic for confidence