BUGFIX:  This change fixes #2475, and incorporates pull request #2806

I think this should handle both the changes from milli's #2806 pull request and my #2809 pull request.