small fix to writing files