Redid database structure

And rewrote queries. Right now there is an unresolved issue with new
rows being in the order array but not the column key reverse lookup
which I'll need to figure out a way around tomorrow.