Work more on refactoring for internal output format.