Solution for Issue #1607

Adds a test for and fixes #1607, see comments in that issue for explanation.