Refactoring inputstream related issues