Use SetCtrlHandler for listening to shutdown