updated output logic