Using slightly better approach to ensure that output can be captured into a string