Added some write_mode code.