add debug statements and fix update_bitstream to include offsets