adding check for existence of query object