Changed length calculation for packets with payload longer than 254 bytes