Refactor I/O setup.