fix crash on domain restart in Agent, also have Agent properly shutdown on call to Script.stop()
Merge pull request #2440 from ZappoMan/fixagentcrash

fix crash on domain restart in Agent, also have Agent properly shutdown on call to Script.stop()