Fixed write_preamble