dry up output formats

Minor refactoring to move common code between output formwats into a shared method.
Merge pull request #8 from mbrookes/dry-up

Dry up output format