Refactorings.
Added basic unit tests.