Implemented part of the ClientAPI (sufficient to send out handshake). Fixed bugs and typos.