refactor I/O