Factor out formatting stuff