Improve output logic