clean up writing of headers