Big refactor + unit test coverage of io.
Run pytests on CI.