some minor fixes. write_to_file() added.