Fixed issue #3 (adpated library code and tests)