some query improvements