Add code to prevent orphaned processes