diff --git a/copilot-c99.cabal b/copilot-c99.cabal
--- a/copilot-c99.cabal
+++ b/copilot-c99.cabal
@@ -1,6 +1,6 @@
 cabal-version             : >= 1.10
 name                      : copilot-c99
-version                   : 3.0.1
+version                   : 3.0.2
 synopsis                  : A compiler for Copilot targeting C99.
 description               :
   This package is a back-end from Copilot to C.
diff --git a/src/Copilot/Compile/C99/External.hs b/src/Copilot/Compile/C99/External.hs
--- a/src/Copilot/Compile/C99/External.hs
+++ b/src/Copilot/Compile/C99/External.hs
@@ -21,8 +21,8 @@
 -- | Collect all external variables from the streams and triggers.
 gatherexts :: [Stream] -> [Trigger] -> [External]
 gatherexts streams triggers = streamsexts `extunion` triggersexts where
-  streamsexts  = concat $ map streamexts streams
-  triggersexts = concat $ map triggerexts triggers
+  streamsexts  = foldr extunion mempty $ map streamexts streams
+  triggersexts = foldr extunion mempty $ map triggerexts triggers
 
   streamexts :: Stream -> [External]
   streamexts (Stream _ _ expr _) = exprexts expr
