fixed null pointer reference of Query