diff --git a/hsp.cabal b/hsp.cabal
--- a/hsp.cabal
+++ b/hsp.cabal
@@ -1,9 +1,9 @@
 Name:                   hsp
-Version:                0.5.1
+Version:                0.5.2
 License:                BSD3
 License-File:           LICENSE
 Author:                 Niklas Broberg, Joel Bjornson
-Maintainer:             Niklas Broberg <nibro@cs.chalmers.se>
+Maintainer:             Niklas Broberg <niklas.broberg@chalmers.se>
 
 Stability:              Experimental
 Category:               Web, Language
@@ -19,18 +19,25 @@
                         .
                         For details on usage, please see the website, and the author's thesis.
 Homepage:               http://code.google.com/p/hsp
-
-Build-Depends:          base >3 && < 4, mtl, harp, hsx>=0.7.0, HJScript>=0.5.0
 Build-Type:             Simple
 Cabal-Version:          >= 1.2.3
 Tested-With:            GHC==6.8.3
 
-Hs-Source-Dirs:         src
-Exposed-Modules:        HSP.XML, HSP.XML.PCDATA, HSP.HTML, HSP.Env, HSP.Env.Request, HSP.Env.NumberGen, HSP.HJScript, HSP
-Other-Modules:          HSP.Exception, HSP.Monad, HSP.XMLGenerator
+Flag base4
 
-GHC-Options:            -Wall -fno-warn-orphans
-Extensions:             MultiParamTypeClasses,
+Library
+  Build-Depends:        base >3 && < 5, mtl, harp, hsx>=0.7.0, HJScript>=0.5.0
+  if flag(base4)
+    Build-depends:      base >= 4 && < 5
+    cpp-options:        -DBASE4
+  else
+    Build-depends:      base >= 3 && < 4
+  Hs-Source-Dirs:       src
+  Exposed-Modules:      HSP.XML, HSP.XML.PCDATA, HSP.HTML, HSP.Env, HSP.Env.Request, HSP.Env.NumberGen, HSP.HJScript, HSP
+  Other-Modules:        HSP.Exception, HSP.Monad, HSP.XMLGenerator
+
+  GHC-Options:          -Wall -fno-warn-orphans
+  Extensions:           MultiParamTypeClasses,
                         FunctionalDependencies,
                         TypeFamilies,
                         RankNTypes,
diff --git a/src/HSP/Exception.hs b/src/HSP/Exception.hs
--- a/src/HSP/Exception.hs
+++ b/src/HSP/Exception.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE CPP #-}
 {-# OPTIONS -fglasgow-exts #-}
 -----------------------------------------------------------------------------
 -- |
@@ -18,8 +19,11 @@
 	) where
 
 import Data.Typeable
+#ifdef BASE4
+import Control.OldException (throwDyn)
+#else
 import Control.Exception (throwDyn)
-
+#endif
 data Exception
 	=  ParameterLookupFailed String	-- ^ User tried to do an irrefutable parameter lookup
 					-- that failed.
diff --git a/src/HSP/Monad.hs b/src/HSP/Monad.hs
--- a/src/HSP/Monad.hs
+++ b/src/HSP/Monad.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE OverlappingInstances, UndecidableInstances #-}
+{-# LANGUAGE CPP, OverlappingInstances, UndecidableInstances #-}
 -----------------------------------------------------------------------------
 -- |
 -- Module      :  HSP.Data
@@ -32,7 +32,11 @@
 import Prelude hiding (catch)
 
 -- Exceptions
+#ifdef BASE4
+import Control.OldException (catchDyn)
+#else
 import Control.Exception (catchDyn)
+#endif
 import HSP.Exception
 
 import HSP.Env
diff --git a/src/HSP/XMLGenerator.hs b/src/HSP/XMLGenerator.hs
--- a/src/HSP/XMLGenerator.hs
+++ b/src/HSP/XMLGenerator.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, OverlappingInstances, PatternGuards, TypeFamilies, TypeSynonymInstances, UndecidableInstances #-}
 {-# OPTIONS_GHC -F -pgmFtrhsx #-}
 module HSP.XMLGenerator (
         -- * Type classes
