bugfix writing output file