Fix for Issue #374, and add regression tests.