Add unit-test for bug #105.
Small code refactoring for better readability