Added test for issue 345. Fixes #345. Fixes #336