More improvements.

I think I'm getting closer to a stable version of this thing now. There
were still problems in the offset of the payload, but it should be okay
now - I had forgotten the header (which isn't part of the remaining
length value).