Also fixed the same thing in file writing code