fix output logic