Fixed some query issues