Refactored console printing code

Refactored console printing code