added if(write_file) in a really dumb way