Dry up output format

Minor refactor to remove duplicate code between output formats.