added connection checking