rewrote terminate_processes() function