Added back code from PR #2728 which was removed in PR #2732.