diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
 # Revision history for mischief-ecs
 
+## 0.2.3.0 
+
+* Fixed a bug when checking for change detection on components that are not yet registered
+* Added compile-time optimizations for query filters when using quasi-queries.  
+
 ## 0.2.2.0 
 
 * Performance improvements when chaining multiple Changed filters with Or. 
diff --git a/mischief-ecs.cabal b/mischief-ecs.cabal
--- a/mischief-ecs.cabal
+++ b/mischief-ecs.cabal
@@ -18,7 +18,7 @@
 -- PVP summary:     +-+------- breaking API changes
 --                  | | +----- non-breaking API additions
 --                  | | | +--- code changes with no API change
-version: 0.2.2.0
+version: 0.2.3.0
 -- A short (one-line) description of the package.
 synopsis: An archetype ECS engine built in Haskell.
 homepage: https://codeberg.org/mischief/mischief
diff --git a/src/Mischief/ECS/World/Query.hs b/src/Mischief/ECS/World/Query.hs
--- a/src/Mischief/ECS/World/Query.hs
+++ b/src/Mischief/ECS/World/Query.hs
@@ -423,12 +423,15 @@
 filterAllArchetypes (Without x) = do
   world <- unsafeGetWorld
   f <- liftIO $ filterToQuery world x
+  maybe allArchetypes archetypesWithout f
+filterAllArchetypes (Changed x f1 f2) = do
+  world <- unsafeGetWorld
+  f <- liftIO $ filterToQuery world x
   case f of
     Nothing -> pure Set.empty
-    Just f -> archetypesWithout f
-filterAllArchetypes (Changed x f1 f2) = do
-  a <- allArchetypes
-  filterArchetypes a (Changed x f1 f2)
+    Just f -> do
+      a <- archetypesWith f
+      filterArchetypes a (Changed x f1 f2)
 filterAllArchetypes (Or a b) = do
   a' <- filterAllArchetypes a
   b' <- filterAllArchetypes b
@@ -453,8 +456,8 @@
   case f of
     Nothing -> pure prev
     Just f -> do
-      a <- archetypesWithout f
-      pure $ Set.intersection prev a
+      a <- archetypesWith f
+      pure $ Set.difference prev a
 filterArchetypes prev (Changed x f1 f2) = do
   -- TODO: use Set.filterA from containers>=0.8.1
   Set.fromList <$> filterM (filterOnlyChanged (Changed x f1 f2)) (Set.toList prev)
diff --git a/src/Mischief/ECS/World/Query/TH/QF.hs b/src/Mischief/ECS/World/Query/TH/QF.hs
--- a/src/Mischief/ECS/World/Query/TH/QF.hs
+++ b/src/Mischief/ECS/World/Query/TH/QF.hs
@@ -12,12 +12,49 @@
 import Text.Megaparsec (MonadParsec (notFollowedBy, try), choice, many, optional, satisfy, some, (<|>))
 import Text.Megaparsec.Char
 
-data Qf = With' [QfType] | Without' [QfType] | Changed' [QfType] Text Text | Tup' [Qf] | And' Qf Qf | Or' Qf Qf deriving (Show)
+data Qf = With' [QfType] | Without' [QfType] | Changed' [QfType] Text Text | And' Qf Qf | Or' Qf Qf | NoFilter' deriving (Show)
 
+type HasWith =
+  Bool
+
+optQf :: Qf -> Qf
+optQf = optF . opt1 . opt0
+
+-- | Flatten Ands and Ors in one direction.
+opt0 :: Qf -> Qf
+opt0 (And' (And' a b) c) = opt0 $ And' a (And' b c)
+opt0 (And' a b) = And' (opt0 a) (opt0 b)
+opt0 (Or' (Or' a b) c) = opt0 $ Or' a (Or' b c)
+opt0 (Or' a b) = Or' (opt0 a) (opt0 b)
+opt0 x = x
+
+-- |
+-- Sort the And chains so that Withs are first, and Withouts second.
+-- Sort the Or chains so that Changed are last.
+opt1 :: Qf -> Qf
+opt1 (And' a (And' (With' b) c)) = And' (With' b) $ opt1 (And' a c)
+opt1 (And' a (And' (Without' b) c)) = And' (Without' b) $ opt1 (And' a c)
+opt1 (Or' (Changed' a a1 a2) b) = Or' (opt1 b) (Changed' a a1 a2)
+opt1 (And' a b) = And' (opt1 a) (opt1 b)
+opt1 (Or' a b) = Or' (opt1 a) (opt1 b)
+opt1 x = x
+
+-- | If possible, ensure that the first filter is not a Without or Or.
+optF :: Qf -> Qf
+optF (And' (Without' a) b) = And' (optF b) (Without' a)
+optF (And' (Or' a b) c) = And' (optF c) (Or' a b)
+optF (Or' a b) = Or' (optF a) (optF b)
+optF x = x
+
+-- optimizeQfFinal
+
 data QfType = QfType {name :: Text, compType :: CompType} deriving (Show)
 
+buildTup :: [Qf] -> Qf
+buildTup = foldl' (flip And') NoFilter'
+
 pQf :: Parser Qf
-pQf = Tup' . concat <$> pTup pTup'
+pQf = optQf . buildTup . concat <$> pTup pTup'
 
 pTup' :: Parser [Qf]
 pTup' = try ((char '(' *> whitespace) *> (concat <$> pTup pTup') <* (char ')' *> whitespace)) <|> (: []) <$> pOr
@@ -113,7 +150,7 @@
       }
 
 quoteQf :: Qf -> Q Exp
-quoteQf (Tup' !qf) = processTup qf
+quoteQf NoFilter' = pure $ ConE 'NoFilter
 quoteQf (With' !x) = processTypes (ConE 'With) x
 quoteQf (Without' !x) = processTypes (ConE 'Without) x
 quoteQf (Changed' !x f1 f2) = do
