Test coverage improved and brittle IO code moved into separate class