refactor IO