Restructured database relationships

Simplified the relationships between the MetaData table and other tables
by using a smaller intermediary table.
Queries should be much easier now.