* query: don't invert if no not clause
* can query for ID directly
* more fixes in query logic