Refactored and added additional unit tests.