fix several bugs in incomming packet parsing