diff --git a/AGI.cabal b/AGI.cabal
--- a/AGI.cabal
+++ b/AGI.cabal
@@ -1,30 +1,44 @@
 Name:           AGI
-Category:	Network
+Category:       Network
 Synopsis:       A library for writing AGI scripts for Asterisk
-Description: Asterisk is an open-source Voice over IP server
- (VoIP). Asterisk provides an Asterisk Gateway Interface (AGI), which
- can be used to write external programs that interact with
- Asterisk. It is typically used for creating Interactive Voice
- Response (IVR) systems. 
-Version:        1.1
+Description:
+     Asterisk is an open-source Voice over IP server (VoIP).
+     Asterisk provides an Asterisk Gateway Interface (AGI), which
+     can be used to write external programs that interact with
+     Asterisk. It is typically used for creating Interactive Voice
+     Response (IVR) systems. 
+Version:        1.1.1
 License:        BSD3
-License-File:	debian/copyright
+License-File:   LICENSE
 Author:         Jeremy Shaw
-Maintainer:	Jeremy Shaw <jeremy@n-heptane.com>
+Maintainer:     Jeremy Shaw <jeremy@n-heptane.com>
 Homepage:       http://www.n-heptane.com/nhlab/repos/haskell-agi
-Build-Depends:  base, parsec, mtl
-Exposed-modules:
-	Network.AGI 
 Extra-Source-Files:
-	debian/changelog  debian/compat  debian/control  debian/copyright  
- 	debian/haskell-agi-doc.docs  debian/rules
-	examples/guessinggame/GuessingGame.hs
-	examples/guessinggame/sounds/guessing-game-correct.gsm
-	examples/guessinggame/sounds/guessing-game-intro.gsm
-	examples/guessinggame/sounds/guessing-game-yay.gsm
-	examples/guessinggame/sounds/guessing-game-higher.gsm
-	examples/guessinggame/sounds/guessing-game-lower.gsm
-	tests/Main.hs
+        debian/changelog  debian/compat  debian/control  debian/copyright  
+        debian/haskell-agi-doc.postinst debian/haskell-agi-doc.postrm debian/rules
+        examples/guessinggame/GuessingGame.hs
+        examples/guessinggame/sounds/guessing-game-correct.gsm
+        examples/guessinggame/sounds/guessing-game-intro.gsm
+        examples/guessinggame/sounds/guessing-game-yay.gsm
+        examples/guessinggame/sounds/guessing-game-higher.gsm
+        examples/guessinggame/sounds/guessing-game-lower.gsm
+        tests/Main.hs
+build-type:     Simple
+cabal-version:       >= 1.2
 
--- For more complex build options see:
--- http://www.haskell.org/ghc/docs/latest/html/Cabal/
+flag small_base
+  description: Choose the new smaller, split-up base package.
+
+library
+    build-depends:  parsec, mtl
+
+    if flag(small_base)
+        build-depends:  base >= 3, random, unix
+    else
+        build-depends:  base <  3
+
+    Exposed-modules:
+            Network.AGI 
+
+    -- For more complex build options see:
+    -- http://www.haskell.org/ghc/docs/latest/html/Cabal/
diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,31 @@
+Copyright (c) 2007, Jeremy Shaw
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+
+    * The names of contributors may not be used to endorse or promote
+      products derived from this software without specific prior
+      written permission. 
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/Network/AGI.hs b/Network/AGI.hs
--- a/Network/AGI.hs
+++ b/Network/AGI.hs
@@ -1,4 +1,4 @@
-{-# OPTIONS_GHC -fglasgow-exts #-}
+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
 module Network.AGI 
     ( Digit(..)
     , AGI
@@ -15,6 +15,7 @@
     , sayNumber
     , streamFile
     , waitForDigit
+    , record
     ) where
 
 import Control.Monad
@@ -75,9 +76,9 @@
     show GSM  = "gsm"
 
 -- TODO: let user install a custom sipHUP handler (sigHUP is sent when the caller hangs ups)
-run :: AGI a -> IO a
-run agi =
-    do installHandler sigHUP Ignore Nothing
+run :: AGI a -> Handler -> IO a
+run agi hupHandler =
+    do installHandler sigHUP hupHandler Nothing
        hSetBuffering stdin LineBuffering
        hSetBuffering stdout LineBuffering
        agiVars <- readAgiVars
@@ -198,20 +199,21 @@
 record :: FilePath -- ^ record to this file
        -> SoundType -- ^ |GSM \| WAV|
        -> [Digit] -- ^ stop recording if one of these digits is entered
-       -> Integer -- ^ maximum record time in milliseconds, -1 for no timeout
+       -> Maybe Integer -- ^ maximum record time in milliseconds, -1 for no timeout
        -> Maybe Integer -- ^ offset samples
        -> Bool -- ^ beep to indicate recording has begun
        -> Maybe Integer -- ^ stop recording if this many seconds of silence passes
        -> AGI (RecordResult, Integer) -- ^ exit condition, endpos=offset
 record fp soundType escapeDigits length offset beep silence =
     do res <- sendRecv $ ("RECORD FILE " ++ fp ++ " " ++ show soundType ++ " " ++ 
-                          ppEscapeDigits escapeDigits ++ " " ++  show length ++  
+                          ppEscapeDigits escapeDigits ++ " " ++  (maybe "-1" show length) ++  
                           (maybe "" (\o -> ' ': show o) offset) ++ 
                           (if beep then " beep" else "") ++
                           (maybe "" (\s -> " s=" ++ show s) silence))
        parseResult p res
+
+p = pResult >> (pFailureToWrite <|> pFailureOnWaitFor <|> pHangUp <|> pInterrupted <|> pTimeout <|> pRandomError)
     where
-      p = pResult >> (pFailureToWrite <|> pFailureOnWaitFor <|> pHangUp <|> pInterrupted <|> pTimeout <|> pRandomError)
       pFailureToWrite = 
           do try (string "-1 (writefile)") >> return (FailureToWrite, 0)
       pFailureOnWaitFor = 
@@ -225,7 +227,7 @@
              ep <- pEndPos
              return (HangUp, ep)
       pInterrupted = try $
-          do digit <- pDigit
+          do digit <- pAsciiDigit
              pSpace
              string "(dtmf)"
              pSpace
diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -2,4 +2,4 @@
 
 import Distribution.Simple
 
-main = defaultMainWithHooks defaultUserHooks
+main = defaultMain
diff --git a/debian/changelog b/debian/changelog
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+haskell-agi (1.1.1) unstable; urgency=low
+
+  * Debianization generated by cabal-debian
+
+ -- Jeremy Shaw <jeremy@n-heptane.com>  Mon, 23 Jun 2008 11:13:22 -0700
+
 haskell-agi (1.1) unstable; urgency=low
 
   * Major rewrite of internals, some API breakage
@@ -9,4 +15,3 @@
   * Initial Debian package.
 
  -- Jeremy Shaw <jeremy@n-heptane.com>  Sat, 12 May 2007 19:54:42 -0700
-
diff --git a/debian/compat b/debian/compat
--- a/debian/compat
+++ b/debian/compat
@@ -1,1 +1,1 @@
-4
+5
diff --git a/debian/control b/debian/control
--- a/debian/control
+++ b/debian/control
@@ -1,45 +1,65 @@
 Source: haskell-agi
 Priority: optional
-Section: devel
+Section: misc
 Maintainer: Jeremy Shaw <jeremy@n-heptane.com>
-Build-Depends: debhelper (>= 4.0.0), haskell-devscripts (>=0.5.12), ghc6 (>=6.4), ghc6-prof
-Build-Depends-Indep: haddock, hugs (>= 98.200503.08)
-Standards-Version: 3.7.2.0
+Build-Depends: debhelper (>= 5.0),
+               haskell-devscripts-cdbs,
+               cabal-debian,
+               ghc6 (>= 6.8),
+               ghc6-doc,
+               haddock (>= 2.1.0),
+               ghc6-prof,
+               libghc6-parsec-prof,
+               libghc6-parsec-doc,
+               libghc6-mtl-prof,
+               libghc6-mtl-doc
+Standards-Version: 3.7.2.2
+Homepage: http://www.n-heptane.com/nhlab/repos/haskell-agi
 
 Package: libghc6-agi-dev
-Section: libdevel
 Architecture: any
+Section: libdevel
 Depends: ${haskell:Depends}
-Description: A Haskell AGI library
- A library for creating applications that can be called from Asterisk
- using the Asterisk Gateway Interface (AGI).
- .
- This package contains the libraries compiled for GHC 6.
+Description: A library for writing AGI scripts for Asterisk
+  Asterisk is an open-source Voice over IP server (VoIP).
+  Asterisk provides an Asterisk Gateway Interface (AGI), which
+  can be used to write external programs that interact with
+  Asterisk. It is typically used for creating Interactive Voice
+  Response (IVR) systems.
+  .
+  Author: Jeremy Shaw
+  Upstream-Maintainer: Jeremy Shaw <jeremy@n-heptane.com>
+  .
+  This package contains the normal library files.
 
 Package: libghc6-agi-prof
-Section: libdevel
 Architecture: any
-Depends: ${haskell:Depends}
-Description: A Haskell AGI library
- A library for creating applications that can be called from Asterisk
- using the Asterisk Gateway Interface (AGI).
- .
- This package contains the libraries compiled for GHC 6 with profiling
- enabled.
-
-Package: libhugs-agi
 Section: libdevel
-Architecture: all
 Depends: ${haskell:Depends}
-Description: A Haskell AGI library
- A library for creating applications that can be called from Asterisk
- using the Asterisk Gateway Interface (AGI).
- .
- This package contains the libraries compiled for Hugs.
+Description: A library for writing AGI scripts for Asterisk
+  Asterisk is an open-source Voice over IP server (VoIP).
+  Asterisk provides an Asterisk Gateway Interface (AGI), which
+  can be used to write external programs that interact with
+  Asterisk. It is typically used for creating Interactive Voice
+  Response (IVR) systems.
+  .
+  Author: Jeremy Shaw
+  Upstream-Maintainer: Jeremy Shaw <jeremy@n-heptane.com>
+  .
+  This package contains the libraries compiled with profiling enabled.
 
 Package: haskell-agi-doc
-Section: doc
 Architecture: all
-Description: Documentation for a Haskell AGI library
- A library for creating applications that can be called from Asterisk
- using the Asterisk Gateway Interface (AGI).
+Section: libdevel
+Depends: ${haskell:Depends}
+Description: A library for writing AGI scripts for Asterisk
+  Asterisk is an open-source Voice over IP server (VoIP).
+  Asterisk provides an Asterisk Gateway Interface (AGI), which
+  can be used to write external programs that interact with
+  Asterisk. It is typically used for creating Interactive Voice
+  Response (IVR) systems.
+  .
+  Author: Jeremy Shaw
+  Upstream-Maintainer: Jeremy Shaw <jeremy@n-heptane.com>
+  .
+  This package contains the documentation files.
diff --git a/debian/haskell-agi-doc.docs b/debian/haskell-agi-doc.docs
deleted file mode 100644
--- a/debian/haskell-agi-doc.docs
+++ /dev/null
@@ -1,1 +0,0 @@
-dist/doc/html
diff --git a/debian/haskell-agi-doc.postinst b/debian/haskell-agi-doc.postinst
new file mode 100644
--- /dev/null
+++ b/debian/haskell-agi-doc.postinst
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Generic doc postinst script for Haskell cabal libraries v9 by Ian Lynagh.
+#
+set -e
+
+# summary of how this script can be called:
+#        * <postinst> `configure' <most-recently-configured-version>
+#        * <old-postinst> `abort-upgrade' <new version>
+#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
+#          <new-version>
+#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
+#          <failed-install-package> <version> `removing'
+#          <conflicting-package> <version>
+# for details, see /usr/doc/packaging-manual/
+#
+# quoting from the policy:
+#     Any necessary prompting should almost always be confined to the
+#     post-installation script, and should be protected with a conditional
+#     so that unnecessary prompting doesn't happen if a package's
+#     installation fails and the `postinst' is called with `abort-upgrade',
+#     `abort-remove' or `abort-deconfigure'.
+
+case "$1" in
+    configure|abort-upgrade|abort-remove|abort-deconfigure)
+        cd /usr/share/doc/ghc6-doc/libraries
+        /usr/lib/ghc6-doc/gen_contents_index
+    ;;
+    *)
+        echo "postinst called with unknown argument \`$1'" >&2
+        exit 0
+    ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0
diff --git a/debian/haskell-agi-doc.postrm b/debian/haskell-agi-doc.postrm
new file mode 100644
--- /dev/null
+++ b/debian/haskell-agi-doc.postrm
@@ -0,0 +1,21 @@
+#! /bin/sh
+# Generic doc postrm script for Haskell cabal libraries v9 by Ian Lynagh.
+
+set -e
+
+DIR=/usr/share/doc/ghc6-doc/libraries
+GEN=/usr/lib/ghc6-doc/gen_contents_index
+
+case "$1" in
+    *)
+        [ -d $DIR ] && [ -e $GEN ] && cd $DIR && $GEN
+    ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0
+
diff --git a/debian/rules b/debian/rules
--- a/debian/rules
+++ b/debian/rules
@@ -1,86 +1,2 @@
 #!/usr/bin/make -f
-
-# Uncomment this to turn on verbose mode.
-#export DH_VERBOSE=1
-
-build: build-stamp
-build-stamp:
-	dh_testdir
-
-	# Add here commands to compile the package.
-	touch build-stamp
-
-clean:
-	dh_testdir
-	dh_testroot
-	rm -f build-stamp
-
-	# Add here commands to clean up after the build process.
-	if [ -x setup ] && [ -e .setup-config ] ; then ./setup clean ; fi
-	rm -rf setup Setup.hi Setup.ho Setup.o .*config* dist html
-	#make clean
-
-	dh_clean 
-
-install: build
-	dh_testdir
-	dh_testroot
-	dh_clean -k 
-	dh_installdirs -a 
-
-	# Add here commands to install the package into debian/tmp
-	dh_haskell -a
-
-build-indep: build-indep-stamp
-build-indep-stamp:
-	dh_testdir
-
-install-indep: build-indep
-	dh_testdir
-	dh_testroot
-	dh_clean -k
-	dh_installdirs -i
-
-	# Add here commands to install the package into debian/tmp
-	dh_haskell -i
-	./Setup.hs haddock
-	#make doc
-
-# Build architecture-independent files here.
-binary-indep: build-indep install-indep
-	dh_testdir
-	dh_testroot
-	dh_installchangelogs -i
-	dh_installdocs -i
-	dh_installexamples -i
-	dh_installman -i
-	dh_link -i
-	dh_strip -i
-	dh_compress -i
-	dh_fixperms -i
-	dh_installdeb -i
-	dh_shlibdeps -i
-	dh_gencontrol -i
-	dh_md5sums -i
-	dh_builddeb -i
-
-# Build architecture-dependent files here.
-binary-arch: build install
-	dh_testdir
-	dh_testroot
-	dh_installchangelogs -a
-	dh_installdocs -a
-	dh_installexamples -a
-	dh_installman -a
-	dh_link -a
-	dh_strip -a
-	dh_compress -a
-	dh_fixperms -a
-	dh_installdeb -a
-	dh_shlibdeps -a
-	dh_gencontrol -a
-	dh_md5sums -a
-	dh_builddeb -a
-
-binary: binary-indep binary-arch
-.PHONY: build clean binary-indep binary-arch binary install build-indep install-indep
+include /usr/share/haskell-devscripts/hlibrary.mk
diff --git a/examples/guessinggame/GuessingGame.hs b/examples/guessinggame/GuessingGame.hs
--- a/examples/guessinggame/GuessingGame.hs
+++ b/examples/guessinggame/GuessingGame.hs
@@ -15,7 +15,7 @@
 
 main :: IO ()
 main =
-       run mainAGI
+       run mainAGI Ignore
 
 mainAGI :: AGI ()
 mainAGI =
