Fixes for the database.
Some bugfixes but queries are not sticking for some reason.