diff --git a/library/Require.hs b/library/Require.hs
--- a/library/Require.hs
+++ b/library/Require.hs
@@ -77,9 +77,9 @@
 transform' :: Bool -> FileName -> Text -> Text -> Text
 transform' shouldPrepend filename prepended input =
   Text.lines input
+  &   filter (\t -> not $ "autorequire" `Text.isPrefixOf` t)
   &   zip [1..]
   >>= prependAfterModuleLine
-  &   filter (\(_, t) -> not $ "autorequire" `Text.isPrefixOf` t)
   <&> (\(ln, text) -> maybe (lineTag filename (LineNumber ln) <> text <> "\n") (renderImport filename (LineNumber ln)) $ Megaparsec.parseMaybe requireParser text )
   &   Text.concat
  where
@@ -87,7 +87,18 @@
    | shouldPrepend = zip (repeat ln) (Text.lines prepended)
    | otherwise     = []
   prependAfterModuleLine (ln, text)
-   | "where" `Text.isInfixOf` text = (ln, text) : enumeratedPrepend (ln)
+   | ("module" `Text.isPrefixOf` text)
+     && ("where" `Text.isSuffixOf`) text = (ln, text) : enumeratedPrepend ln
+   | ("instance" `Text.isPrefixOf` text)
+     && ("where" `Text.isSuffixOf`) text = [(ln, text)]
+   | ("data" `Text.isPrefixOf` text)
+     && ("where" `Text.isSuffixOf`) text = [(ln, text)]
+   | ("class" `Text.isPrefixOf` text)
+     && ("where" `Text.isSuffixOf`) text = [(ln, text)]
+   | (not $ "instance" `Text.isPrefixOf` text)
+     && (not $ "class" `Text.isPrefixOf` text)
+     && (not $ "data" `Text.isPrefixOf` text)
+     && ("where" `Text.isPrefixOf`) text = (ln, text) : enumeratedPrepend (ln)
    | otherwise                      = [(ln, text)]
 
 lineTag :: FileName -> LineNumber -> Text
diff --git a/package.yaml b/package.yaml
--- a/package.yaml
+++ b/package.yaml
@@ -1,5 +1,5 @@
 name: require
-version: '0.3.2'
+version: '0.4.0'
 github: "theam/require"
 license: Apache-2.0
 author: "The Agile Monkeys"
diff --git a/require.cabal b/require.cabal
--- a/require.cabal
+++ b/require.cabal
@@ -2,10 +2,10 @@
 --
 -- see: https://github.com/sol/hpack
 --
--- hash: 6b852da4ce674b61b22cb631128b49f5bf0b519a9469f54be7372deb92dbf099
+-- hash: 8f222d0ce5d76ff45c88779da37cb9591e547d814faa2c17ac9f171f536c61d6
 
 name:           require
-version:        0.3.2
+version:        0.4.0
 synopsis:       Scrap your qualified import clutter
 description:    See <https://theam.github.io/require>
 category:       Other
