fixed file writing