better handling of the query ref