Unit tests. Further refactoring.