Initial implementation. Lots of tests are missing.