Issue #309: bugfix and test case