Fix bugs in telnet handling.