Refactored code and updated test-cases.