If you have trouble with the process ending cleanly, I'd also try putting a temporary button alongside the runAsync/client.connect and see if doing the connection followed by a manual disconnect() ended things cleanly. Then, if that works, automate it using the Stage method.