Bugfix in database code