added connection erorr handling