fix bug in handle_write()