Re-submitting patch that closes #5989