Fix for issues #3 and #4 with regression test for #3