Issue #215: add tests cases and fix a minor bug (which is why tests cases are important)