fix issue where file isnt written