Reimplementation of BioCWriter; fix some bugs