Refactoring.
Added tests.