BUGFIX:Errors in writing files