On terminate event.