fix logic error in connection checking