Rework things to be more easily understood. Add more tests.