add terminal handler