updated query code