Fix for issue #268 and unit tests for it