i/o tests and refactor