Update building of query