Unit tests

Some refactoring to domain layer and started unit and integration tests