finish to port Mode class from ruby and write tests for it, add Domain class with tests