fixed deadlock in protocol, various bug fixes