Updated with listener for terminal events.