fix connection handling