General changes to return handling, shutdown function, pid overwrite and removal and exception handling

The signal handler routine should be attached outside of the definition, I saw that it was correctly done in the original patch but somehow got mangled