Refactored domain, added tests.