Fixing Issue #38 and adding unit tests