Make small refactoring and add tests.