Remove duplication in IO handling