updating query logic