Fixed issues #11 (partly) and #16

Needs more work, but it’s enough for today…
Refactored the fix for issue #14

The former solution did not cover all use cases and needed some
additional code to make it all work as expected.
Merge pull request #17 from svanharmelen/development

Development