Fixed some database problems and tests.