Fix for #357/#331
Add a regression test