refactoring of accessing I/O streams