Added handling code so that all child processes are shut down correctly