Refactored code to make printing separate functions