fixed: avoid duplicated write to string
tweak: declare suffix of output file in the header