Refactor output printing.