add terminate callback