Updated example with query state operation