corrected issue with writing to files