diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+v1.1.1.6:
+* Fix a bug in alpha-renaming (thanks Bertram Felgenhauer)
+* Exit nonzero on parse failures (thanks meck)
+
 v1.1.1.5:
 * Metadata fixes and dependency update for base 4.12, containers 0.6, QuickCheck 2.12 (thanks Bryan Gardiner)
 
diff --git a/Main.hs b/Main.hs
--- a/Main.hs
+++ b/Main.hs
@@ -7,6 +7,7 @@
 import Plugin.Pl.Transform
 
 import System.Environment (getArgs)
+import System.Exit (die)
 import System.Console.GetOpt
 
 data Flag = Verbose 
@@ -52,5 +53,5 @@
                putStrLn "Optimized expression:"
                mapM_ (putStrLn . prettyTopLevel) $ mapTopLevel' optimize d'
        else putStrLn . prettyTopLevel . last . mapTopLevel' optimize $ mapTopLevel transform d
-  Left err -> putStrLn err
+  Left err -> die err
 
diff --git a/Plugin/Pl/Transform.hs b/Plugin/Pl/Transform.hs
--- a/Plugin/Pl/Transform.hs
+++ b/Plugin/Pl/Transform.hs
@@ -60,15 +60,17 @@
 unLet (Lambda v e) = Lambda v (unLet e)
 unLet (Var f x) = Var f x
 
-type Env = M.Map String String
+type Env = (M.Map String String, Int)
+-- note: The second component is the environment size, counting duplicate
+-- variables.
 
 -- It's a pity we still need that for the pointless transformation.
 -- Otherwise a newly created id/const/... could be bound by a lambda
 -- e.g. transform' (\id x -> x) ==> transform' (\id -> id) ==> id
 alphaRename :: Expr -> Expr
-alphaRename e = alpha e `evalState` M.empty where
+alphaRename e = alpha e `evalState` (M.empty, 0) where
   alpha :: Expr -> State Env Expr
-  alpha (Var f v) = do fm <- get; return $ Var f $ maybe v id (M.lookup v fm)
+  alpha (Var f v) = do (fm, _) <- get; return $ Var f $ maybe v id (M.lookup v fm)
   alpha (App e1 e2) = liftM2 App (alpha e1) (alpha e2)
   alpha (Let _ _) = assert False bt
   alpha (Lambda v e') = inEnv $ liftM2 Lambda (alphaPat v) (alpha e')
@@ -78,9 +80,9 @@
   inEnv f = gets $ evalState f
 
   alphaPat (PVar v) = do
-    fm <- get
-    let v' = "$" ++ show (M.size fm)
-    put $ M.insert v v' fm
+    (fm, i) <- get
+    let v' = "$" ++ show i
+    put (M.insert v v' fm, i+1)
     return $ PVar v'
   alphaPat (PTuple p1 p2) = liftM2 PTuple (alphaPat p1) (alphaPat p2)
   alphaPat (PCons p1 p2) = liftM2 PCons (alphaPat p1) (alphaPat p2)
diff --git a/pointfree.cabal b/pointfree.cabal
--- a/pointfree.cabal
+++ b/pointfree.cabal
@@ -1,7 +1,7 @@
 Cabal-Version: >= 1.8
 
 Name:     pointfree
-Version:  1.1.1.5
+Version:  1.1.1.6
 Category: Tool
 Synopsis: Tool for refactoring expressions into pointfree form
 
diff --git a/test/Test.hs b/test/Test.hs
--- a/test/Test.hs
+++ b/test/Test.hs
@@ -188,7 +188,8 @@
   unitTest "\\b -> (\\c -> ((Control.Monad.>>=) c) (\\g -> Control.Applicative.pure (b g)))"
     ["flip (Control.Monad.>>=) . (Control.Applicative.pure .)"],
   unitTest "\\(x, y) -> z" ["const z"],
-  unitTest "\\(x, y) -> a" ["const a"]
+  unitTest "\\(x, y) -> a" ["const a"],
+  unitTest "\\x -> \\x y -> x" ["const const"]
   ]
 
 main :: IO ()
