Fixes for issues #47 and #55 including new test cases.