Corrected query bug