Refactored printing to stdout