Adding retry and safe bail out on connection error