added write_flag reset to false and psuedo halt