refactor IO internals