More robust connection handling (hopefully)