Refactor file io to utils