fix database query errors