Fixed critical query bug