Refactored the database layout

Backwards incompatible changes.