Refactoring and fixed bug in unpacking of negotiation cmds.