bugfix writing headers