Converting comments to entities (rebased #5655)

This replaces PRs: #5655, #5449, #365

AFAIK the only remaining issue is performance of the upgrade. My hunch is the annotation deletion is the slow part.