#14 some improvements as hinted in code review by Sjaak, added / extended some test cases