Started with unit tests and related refactoring.