Refactored code and added comments.
Refactored code.
Added test case.