Issue #167: fixed some failing unit tests & added additional tests on some corner cases.