Refactor script so that it writes the comments ordered by id.