moved the code in write_headers() to build_message()