Refactor input-output