added streamwritebit and minor changes