Refactor output functions