Backport of most of #6827 by J Bradshaw with additional modifications (and some reverts) during review. closes #6827