Fixes to database queries.