Issue 517

For issue #517, postponed to 5.0.6.