refactoring I/O