Various fixes and clean-ups.

1.  Fixed an arithmetic bug in computing the timestamp

2.  Chunk length field now works as originally intended, and
    is reduced to a uint16_t