Issue #12: Refactored code and tests