Fixed Bug with writing files