diff --git a/AddHandler.hs b/AddHandler.hs
--- a/AddHandler.hs
+++ b/AddHandler.hs
@@ -1,13 +1,13 @@
+{-# LANGUAGE PatternGuards #-}
 module AddHandler (addHandler) where
 
 import Prelude hiding (readFile)
 import System.IO (hFlush, stdout)
 import Data.Char (isLower, toLower, isSpace)
-import Data.List (isPrefixOf, isSuffixOf)
+import Data.List (isPrefixOf, isSuffixOf, stripPrefix)
 import qualified Data.Text as T
 import qualified Data.Text.IO as TIO
 import System.Directory (getDirectoryContents, doesFileExist)
-import Control.Monad (when)
 
 -- strict readFile
 readFile :: FilePath -> IO String
@@ -62,18 +62,18 @@
 fixApp name =
     unlines . reverse . go . reverse . lines
   where
-    l = "import Handler." ++ name
+    l spaces = "import " ++ spaces ++ "Handler." ++ name
 
-    go [] = [l]
+    go [] = [l ""]
     go (x:xs)
-        | "import Handler." `isPrefixOf` x = l : x : xs
+        | Just y <- stripPrefix "import " x, "Handler." `isPrefixOf` dropWhile (== ' ') y = l (takeWhile (== ' ') y) : x : xs
         | otherwise = x : go xs
 
 fixCabal :: String -> String -> String
 fixCabal name =
     unlines . reverse . go . reverse . lines
   where
-    l = "import Handler." ++ name
+    l = "                  Handler." ++ name
 
     go [] = [l]
     go (x:xs)
diff --git a/yesod-bin.cabal b/yesod-bin.cabal
--- a/yesod-bin.cabal
+++ b/yesod-bin.cabal
@@ -1,5 +1,5 @@
 name:            yesod-bin
-version:         1.4.0.4
+version:         1.4.0.5
 license:         MIT
 license-file:    LICENSE
 author:          Michael Snoyman <michael@snoyman.com>
