Refactored database stuff to make it easier to work with. WARNING: everything is broken because of some sort of bug in the database