implemented writeStream and added tests for it