Fixed env checking and Added the signal hook.