This commit should make the 'stay connected' option more resilient to failure.