cleaner way to rewrite output