Fix some bugs in streaming writer with shared bnodes.
Fix problems in writer where the same bnode is shared in multiple contexts.