Mostly done now, tests added, all passing.