better error logging and some fixes for the protocol.