add writeNS. use StringBuilders instead of string concatenation