added query and query matches handling