New query code structure