Reorganize code, start testing in earnest

WARNING: test logging abounds.