Initial working code and tests.