Fixed bug in payload length calculation.