Redo some structure, add some more tests.