diff --git a/ChangeLog.md b/ChangeLog.md
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,6 +1,11 @@
 # Revision history for Selda
 
 
+## 0.1.10.1 -- 2017-08-11
+
+* Fix name generation in the presence of multiple aggregates.
+
+
 ## 0.1.10.0 -- 2017-08-01
 
 * Async exception safety.
diff --git a/selda.cabal b/selda.cabal
--- a/selda.cabal
+++ b/selda.cabal
@@ -1,5 +1,5 @@
 name:                selda
-version:             0.1.10.0
+version:             0.1.10.1
 synopsis:            Type-safe, high-level EDSL for interacting with relational databases.
 description:         This package provides an EDSL for writing portable, type-safe, high-level
                      database code. Its feature set includes querying and modifying databases,
diff --git a/src/Database/Selda/Query.hs b/src/Database/Selda/Query.hs
--- a/src/Database/Selda/Query.hs
+++ b/src/Database/Selda/Query.hs
@@ -96,14 +96,11 @@
           => Query (Inner s) a
           -> Query s (OuterCols a)
 aggregate q = Query $ do
-  -- Run query in isolation, then rename the remaining vars and generate outer
-  -- query.
-  st <- get
   (gst, aggrs) <- isolate q
   cs <- mapM rename $ unAggrs aggrs
   let sql = state2sql gst
       sql' = SQL cs (Product [sql]) [] (groupCols gst) [] Nothing
-  put $ st {sources = sql' : sources st}
+  modify $ \st -> st {sources = sql' : sources st}
   pure $ toTup [n | Named n _ <- cs]
 
 -- | Perform a @LEFT JOIN@ with the current result set (i.e. the outer query)
