Refactor the print functionality.