added connection error handling