Add test for issue #40
Fix issue #40 using patch from wylee