tested and fixed StreamWriter