finished IO refactor, untested