Refactoring and code clean up over writable stream