Bugfixes

Fix errors in database library.