Fix issue #304 and add test.