fix some query problems