added undefined check for job.shell.onExit and job.shell.onConnect