Extract shell spawning into a separate function