Refactoring and additional unit tests.