Refactoring and add first correct unit-test.