Fix issue #567 and add test.