Fix on_close problem