Added a while loop to prevent bad TELNET results from escaping into the code.