fixing file writing