Corrected compiler errors and warnings.

This have accumulated over the last dozen or so commits.

These should be merged into the '3.1.x' branch and cherry-picked into the 'master' branch.