Converting comments to entities

This replaces PRs: #5682, #5655, #5449, #365

It is a rebase of #5682