Refactoring. Adding unit test.