fix for issue #306 and a new test