Bugfix in write_to_disk function.