Clean-up the code base (6.x)

Backport of #474 to 6.x.