Fix a number of wrong variable names and similar items.

This replaces the previous pull request #1107 and is for master only.  Two of the issues from the original PR #1102 are being handled separately.