Refactored console printing code