Fix for #299, including test.