fixed bug with writing new file