Fixed some problems with querys