The escaping of the main shell script is also tidied up, and some processes that were spawned for no reason are removed.