Added sorting of documents within each group.