Fixed bugs from async writeFile