refactor io handler