Sweeping changes.

Massive changes to database structure and associated models. Added test helpers and tests on the helpers.