updated query functionality