Some style fixes
Use do_write function in place of self-written replacement