Cleaned up code further and made the connection from the client and telnet more robust (better error handling and better feedback).