almost done i/o refactor