Fixes #18

...again. This time a slightly better approach.
Added a test case for #18