refactor file to io