Patch to fix issue #5.
Added a test case for #5, confirming the bug.