added checks for connection errors