Fix database queries