Serialization of BitSet failed when the existing bit was already set

This patch both clears empty bitset bits and pads the bitset out to the end of the last byte.