Further refactoring. Basic test added.