Fix header writing