added code to cope with 'telnet' connections