Start of database model stuff. Also some other fixes.