first working implementation. more tests on the way