loader: improve writing of headers