diff --git a/FileNameUtils.lhs b/FileNameUtils.lhs
--- a/FileNameUtils.lhs
+++ b/FileNameUtils.lhs
@@ -1,9 +1,10 @@
 > {-# LANGUAGE ScopedTypeVariables #-}
-> {-# LANGUAGE PatternSignatures #-}
 >
 > module FileNameUtils          ( extension
 >                               , expandPath
 >                               , chaseFile
+>                               , readTextFile
+>                               , openOutputFile
 >                               , modifySearchPath
 >                               , deep, env
 >                               , absPath
@@ -11,8 +12,7 @@
 >                               ) where
 >
 > import Prelude hiding         (  catch, readFile )
-> import System.IO              (  openFile, IOMode(..) )
-> import System.IO.UTF8
+> import System.IO              (  openFile, IOMode(..), hSetEncoding, hGetContents, utf8, Handle() )
 > import System.Directory
 > import System.Environment
 > import Data.List
@@ -111,12 +111,15 @@
 >                                    s' -> w : splitOn p s''
 >                                            where (w,s'') = break p s'
 
-The UTF8 version of readFile defaults to binary files, whereas the
-System.IO version defaults to text files. Therfore we implement our
-own.
-
 > readTextFile                  :: FilePath -> IO String
-> readTextFile f                =  openFile f ReadMode >>= hGetContents
+> readTextFile f                =  do h <- openFile f ReadMode
+>                                     hSetEncoding h utf8
+>                                     hGetContents h
+
+> openOutputFile                :: FilePath -> IO Handle
+> openOutputFile f              =  do h <- openFile f WriteMode
+>                                     hSetEncoding h utf8
+>                                     return h
 
 > chaseFile                     :: [String]    {- search path -}
 >                               -> FilePath -> IO (String,FilePath)
diff --git a/INSTALL b/INSTALL
--- a/INSTALL
+++ b/INSTALL
@@ -32,7 +32,7 @@
 Unpack the archive. Assume that it has been unpacked into directory
 "/somewhere". Then say
 
-cd /somewhere/lhs2TeX-1.15
+cd /somewhere/lhs2TeX-1.16
 ./configure
 make
 make install
@@ -48,18 +48,18 @@
 lhs2TeX binary. The default search path is as follows:
 
 .
-{HOME}/lhs2tex-1.15//
+{HOME}/lhs2tex-1.16//
 {HOME}/lhs2tex//
 {HOME}/lhs2TeX//
-{HOME}/.lhs2tex-1.15//
+{HOME}/.lhs2tex-1.16//
 {HOME}/.lhs2tex//
 {HOME}/.lhs2TeX//
 {LHS2TEX}//
-/usr/local/share/lhs2tex-1.15//
-/usr/local/share/lhs2tex-1.15//
-/usr/local/lib/lhs2tex-1.15//
-/usr/share/lhs2tex-1.15//
-/usr/lib/lhs2tex-1.15//
+/usr/local/share/lhs2tex-1.16//
+/usr/local/share/lhs2tex-1.16//
+/usr/local/lib/lhs2tex-1.16//
+/usr/share/lhs2tex-1.16//
+/usr/lib/lhs2tex-1.16//
 /usr/local/share/lhs2tex//
 /usr/local/lib/lhs2tex//
 /usr/share/lhs2tex//
diff --git a/Library/beamerboxed.fmt b/Library/beamerboxed.fmt
new file mode 100644
--- /dev/null
+++ b/Library/beamerboxed.fmt
@@ -0,0 +1,45 @@
+%if False
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% beamerboxed.fmt
+%
+% Displaying code that is set with lhs2TeX in poly style inside boxes from the
+% beamer class.
+%
+% Permission is granted to include this file (or parts of this file) literally
+% into other documents, regardless of the conditions or license applying to
+% these documents.
+%
+% Stefan Holdermans, April 2010, version 1.0
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%endif
+%if not lhs2tex_beamerboxed_fmt_read
+%let lhs2tex_beamerboxed_fmt_read = True
+%include polycode.fmt
+%include beamer.fmt
+%
+%if style /= newcode
+\ReadOnlyOnce{beamerboxed.fmt}
+
+\setbeamercolor{hsbox}{parent=block body}
+\newlength{\hsboxsep}
+\setlength{\hsboxsep}{.33em}
+\newcommand{\hsboxrounded}{true}
+\newcommand{\hsboxshadow}{true}
+
+\newenvironment{beamerboxedhscode}
+  {\let\hspre\(\let\hspost\)%
+   \beamercolorbox%
+     [sep=\hsboxsep,rounded=\hsboxrounded,shadow=\hsboxshadow]%
+     {hsbox}%
+   \hscodestyle%
+   \pboxed}%
+  {\endpboxed%
+   \endbeamercolorbox%
+   \ignorespacesafterend}
+
+\newcommand{\beamerboxedhs}{\sethscode{beamerboxedhscode}}
+
+\EndFmtInput
+%endif
+%endif
diff --git a/Main.lhs b/Main.lhs
--- a/Main.lhs
+++ b/Main.lhs
@@ -9,8 +9,7 @@
 >
 > import Data.Char ( isSpace )
 > import Data.List ( isPrefixOf )
-> import System.IO ( hClose, hFlush, stderr, stdout, openFile, IOMode(..), Handle(..) )
-> import System.IO.UTF8 ( hPutStr, hPutStrLn, hGetLine, getContents )
+> import System.IO
 > import System.Directory ( copyFile )
 > import System.Console.GetOpt
 > import Text.Regex ( matchRegex, mkRegexWithOpts )
@@ -50,7 +49,10 @@
 
 > main'                         :: [String] -> IO ()
 > main' args                    =  case getOpt Permute options args of
->   (o,n,[])                    -> do (flags,initdirs,styles) 
+>   (o,n,[])                    -> do hSetEncoding stdin  utf8
+>                                     hSetEncoding stdout utf8
+>                                     hSetEncoding stderr utf8
+>                                     (flags,initdirs,styles) 
 >                                        <- foldM (\(s,d,x) (sf,df,ns) -> do s' <- sf s
 >                                                                            return (s',df d,ns ++ x))
 >                                                 (state0,[],[]) o
@@ -85,7 +87,7 @@
 > type CondInfo                 =  (FilePath, LineNo, Bool, Bool)
 
 > data State                    =  State { style      :: Style,
->                                          lang       :: Lang,
+>                                          lang       :: Lang,          -- Haskell or Agda, currently
 >                                          verbose    :: Bool,
 >                                          searchpath :: [FilePath],
 >                                          file       :: FilePath,      -- also used for `hugs'
@@ -167,12 +169,12 @@
 >                                  else do c <- readFile f1
 >                                          case matchRegex (mkRegexWithOpts "^%include" True False) c of
 >                                            Nothing -> if lit then
->                                                          do h <- openFile f3 WriteMode
+>                                                          do h <- openOutputFile f3
 >                                                             lhs2TeX NewCode (flags { output = h }) (Directive Include "lhs2TeX.fmt" : dirs) [f1]
 >                                                             hClose h
 >                                                       else copyFile f2 f3
 >                                            Just _  -> -- supposed to be an lhs2TeX file
->                                                       do h <- openFile f3 WriteMode
+>                                                       do h <- openOutputFile f3
 >                                                          lhs2TeX NewCode (flags { output = h }) dirs [f1]
 >                                                          hClose h
 > preprocess _ _ _ _            =  error "preprocess: too few arguments"
@@ -219,7 +221,7 @@
 >   , Option []    ["haskell"] (NoArg (\s -> return $ s { lang = Haskell}, id, []))         "Haskell lexer (default)"
 >   , Option []    ["agda"]    (NoArg (\s -> return $ s { lang = Agda}, id, []))            "Agda lexer"
 >   , Option []    ["pre"]     (NoArg (return, id, [Pre]))                                  "act as ghc preprocessor"
->   , Option ['o'] ["output"]  (ReqArg (\f -> (\s -> do h <- openFile f WriteMode
+>   , Option ['o'] ["output"]  (ReqArg (\f -> (\s -> do h <- openOutputFile f
 >                                                       return $ s { output = h }, id, [])) "file") "specify output file"
 >   , Option []    ["file-directives"]
 >                              (NoArg (\s -> return $ s { fldir = True }, id, []))          "generate %file directives"
@@ -228,8 +230,8 @@
 >   , Option ['A'] ["align"]   (ReqArg (\c -> (return, (Directive Align c:), [])) "col")    "align at <col>"
 >   , Option ['i'] ["include"] (ReqArg (\f -> (return, (Directive Include f:), [])) "file") "include <file>"
 >   , Option ['l'] ["let"]     (ReqArg (\s -> (return, (Directive Let s:), [])) "equation") "assume <equation>"
->   , Option ['s'] ["set"]     (ReqArg (\s -> (return, (Directive Let (s ++ "=True"):), [])) "flag")  "set <flag>"
->   , Option ['u'] ["unset"]   (ReqArg (\s -> (return, (Directive Let (s ++ "=False"):), [])) "flag") "unset <flag>"
+>   , Option ['s'] ["set"]     (ReqArg (\s -> (return, (Directive Let (s ++ " = True"):), [])) "flag")  "set <flag>"
+>   , Option ['u'] ["unset"]   (ReqArg (\s -> (return, (Directive Let (s ++ " = False"):), [])) "flag") "unset <flag>"
 >   , Option ['P'] ["path"]    (ReqArg (\p -> (\s -> return $ s { searchpath = modifySearchPath (searchpath s) p }, id , [])) "path") 
 >                                                                                       "modify search path"
 >   , Option []    ["searchpath"]
@@ -304,9 +306,16 @@
 >                                          inline result
 > format (Command Perform s)    =  do st <- fetch
 >                                     unless (style st `elem` [CodeOnly,NewCode]) $
->                                       do result <- external s
->                                          out (Text (trim result))
+>                                       do result <- external (map unNL s)
+>                                          update (\st@State{file = f', lineno = l'} ->
+>                                                    st{file = "<perform>", files = (f', l') : files st})
+>                                          fromIO (when (verbose st) (hPutStr stderr $ "(" ++ "<perform>"))
+>                                          formatStr (addEndNL result)
+>                                          update (\st'@State{files = (f, l) : fs} ->
+>                                                    st'{file = f, lineno = l, files = fs})
+>                                          fromIO (when (verbose st) (hPutStrLn stderr $ ")"))
 >     where
+>     addEndNL                  =  (++"\n") . unlines . lines
 
 Remove trailing blank line.
 
@@ -322,11 +331,11 @@
 > format (Environment Spec s)   =  do st <- fetch
 >                                     unless (style st `elem` [CodeOnly,NewCode]) $
 >                                       display s
-> format (Environment Evaluate s )
+> format (Environment Evaluate s)
 >                               =  do st <- fetch
->                                     result <- external (map unNL s)
->                                     --fromIO (hPutStrLn stderr result)        -- TEST
->                                     display result
+>                                     unless (style st `elem` [CodeOnly,NewCode]) $
+>                                       do result <- external s
+>                                          display result
 > format (Environment Hide s)   =  return ()
 > format (Environment Ignore s) =  return ()
 > format (Environment (Verbatim b) s)
@@ -648,7 +657,7 @@
 
 > programInfo                   :: String
 > programInfo                   =
->     "lhs2TeX " ++ version ++ ", Copyright (C) 1997-2009 Ralf Hinze, Andres Loeh\n\n\
+>     "lhs2TeX " ++ version ++ ", Copyright (C) 1997-2010 Ralf Hinze, Andres Loeh\n\n\
 >     \lhs2TeX comes with ABSOLUTELY NO WARRANTY;\n\
 >     \for details type `lhs2TeX --warranty'.\n\
 >     \This is free software, and you are welcome to redistribute it\n\
diff --git a/RELEASE b/RELEASE
--- a/RELEASE
+++ b/RELEASE
@@ -1,5 +1,5 @@
 
-                     lhs2TeX version 1.14
+                     lhs2TeX version 1.16
                      ====================
 
 We are pleased to announce a new release of lhs2TeX, 
@@ -20,17 +20,14 @@
 
 * A manual explaining all the important aspects of lhs2TeX.
 
-Changes (w.r.t. lhs2TeX 1.13)
+Changes (w.r.t. lhs2TeX 1.15)
 -----------------------------
 
-* Compatible with cabal-1.6; traditional configure/make
-  installation should still work.
-
-* Unicode support.
+* Fixes for UTF8 and ghc-6.12
 
-* Support for Agda's lexing rules (via --agda flag).
+* \perform output is now run through lhs2TeX again
 
-* Minor bugfixes.
+* Some smaller bugfixes
 
 Requirements and Download
 -------------------------
@@ -41,13 +38,12 @@
 
 and, of course, via Hackage:
 
-  http://hackage.haskell.org/cgi-bin/hackage-scripts/package/lhs2tex
+  http://hackage.haskell.org/package/lhs2tex
 
 Should work on all major platforms, but has mainly been
 tested on Linux. Binaries will be made available on request.
 
-You need a recent version of GHC (6.8.{2,3} are tested, older versions
-might work) to build lhs2TeX, and, of course, you need a TeX
+You need GHC 6.12 to build lhs2TeX, and, of course, you need a TeX
 distribution to make use of lhs2TeX's output. The program includes
 a configuration that is suitable for use with LaTeX. In theory, 
 there should be no problem to generate code for other TeX 
@@ -55,7 +51,6 @@
 
 
   Happy lhs2TeXing,
-  Andres Loeh and Ralf Hinze
+  Andres Loeh
 
   lhs2TeX@andres-loeh.de
-  ralf@informatik.uni-bonn.de
diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -34,7 +34,7 @@
 minPolytableVersion = [0,8,2]
 shortversion = show (numversion `div` 100) ++ "." ++ show (numversion `mod` 100)
 version = shortversion ++ if ispre then "pre" ++ show pre else ""
-numversion = 115
+numversion = 116
 ispre = False
 pre = 1
 
diff --git a/configure b/configure
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.63 for lhs2tex 1.15.
+# Generated by GNU Autoconf 2.63 for lhs2tex 1.16.
 #
 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
 # 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
@@ -594,8 +594,8 @@
 # Identity of this package.
 PACKAGE_NAME='lhs2tex'
 PACKAGE_TARNAME='lhs2tex'
-PACKAGE_VERSION='1.15'
-PACKAGE_STRING='lhs2tex 1.15'
+PACKAGE_VERSION='1.16'
+PACKAGE_STRING='lhs2tex 1.16'
 PACKAGE_BUGREPORT=''
 
 ac_subst_vars='LTLIBOBJS
@@ -1230,7 +1230,7 @@
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures lhs2tex 1.15 to adapt to many kinds of systems.
+\`configure' configures lhs2tex 1.16 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1291,7 +1291,7 @@
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of lhs2tex 1.15:";;
+     short | recursive ) echo "Configuration of lhs2tex 1.16:";;
    esac
   cat <<\_ACEOF
 
@@ -1368,7 +1368,7 @@
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-lhs2tex configure 1.15
+lhs2tex configure 1.16
 generated by GNU Autoconf 2.63
 
 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
@@ -1382,7 +1382,7 @@
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by lhs2tex $as_me 1.15, which was
+It was created by lhs2tex $as_me 1.16, which was
 generated by GNU Autoconf 2.63.  Invocation command line was
 
   $ $0 $@
@@ -1751,9 +1751,9 @@
 
 
 
-VERSION="1.15"
-SHORTVERSION="1.15"
-NUMVERSION=115
+VERSION="1.16"
+SHORTVERSION="1.16"
+NUMVERSION=116
 PRE=1
 
 
@@ -3301,7 +3301,7 @@
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by lhs2tex $as_me 1.15, which was
+This file was extended by lhs2tex $as_me 1.16, which was
 generated by GNU Autoconf 2.63.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -3351,7 +3351,7 @@
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_version="\\
-lhs2tex config.status 1.15
+lhs2tex config.status 1.16
 configured by $0, generated by GNU Autoconf 2.63,
   with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
 
diff --git a/doc/CompleteDirectives.lhs b/doc/CompleteDirectives.lhs
--- a/doc/CompleteDirectives.lhs
+++ b/doc/CompleteDirectives.lhs
@@ -2,11 +2,16 @@
 
 \begingroup
 \invisiblecomments
+\def\bropen{@{@}
+\def\brclos{@}@}
+%{
+%format bropen = "\bropen"
+%format brclose = "\brclos"
 \begin{code}
 dir(include)              -- include a file
 dir(format)               -- formatting directive for an identifer/operator
-dir({)                    -- begin of an @lhs2TeX@ group
-dir(})                    -- end of an @lhs2TeX@ group
+dir(bropen)               -- begin of an @lhs2TeX@ group
+dir(brclose)              -- end of an @lhs2TeX@ group
 dir(^let^)                -- set a toggle
 dir(^if^)                 -- test a condition
 dir(^else^)               -- second part of conditional
@@ -19,4 +24,5 @@
 dir(subst)                -- primitive formatting directive
 dir(file)                 -- set filename
 \end{code}
+%}
 \endgroup
diff --git a/doc/Guide2.pdf b/doc/Guide2.pdf
Binary files a/doc/Guide2.pdf and b/doc/Guide2.pdf differ
diff --git a/doc/RawSearchPath.lhs b/doc/RawSearchPath.lhs
--- a/doc/RawSearchPath.lhs
+++ b/doc/RawSearchPath.lhs
@@ -1,17 +1,17 @@
 \begin{code}
 .
-{HOME}/lhs2tex-1.15//
+{HOME}/lhs2tex-1.16//
 {HOME}/lhs2tex//
 {HOME}/lhs2TeX//
-{HOME}/.lhs2tex-1.15//
+{HOME}/.lhs2tex-1.16//
 {HOME}/.lhs2tex//
 {HOME}/.lhs2TeX//
 {LHS2TEX}//
-/usr/local/share/lhs2tex-1.15//
-/usr/local/share/lhs2tex-1.15//
-/usr/local/lib/lhs2tex-1.15//
-/usr/share/lhs2tex-1.15//
-/usr/lib/lhs2tex-1.15//
+/usr/local/share/lhs2tex-1.16//
+/usr/local/share/lhs2tex-1.16//
+/usr/local/lib/lhs2tex-1.16//
+/usr/share/lhs2tex-1.16//
+/usr/lib/lhs2tex-1.16//
 /usr/local/share/lhs2tex//
 /usr/local/lib/lhs2tex//
 /usr/share/lhs2tex//
diff --git a/lhs2tex.cabal b/lhs2tex.cabal
--- a/lhs2tex.cabal
+++ b/lhs2tex.cabal
@@ -1,9 +1,9 @@
 cabal-version:  >=1.6
 name:		lhs2tex
-version:	1.15
+version:	1.16
 license:	GPL
 license-file:	LICENSE
-author:		Ralf Hinze <ralf@informatik.uni-bonn.de>, Andres Loeh <lhs2tex@andres-loeh.de>
+author:		Ralf Hinze <ralf.hinze@comlab.ox.ac.uk>, Andres Loeh <lhs2tex@andres-loeh.de>
 maintainer:	Andres Loeh <lhs2tex@andres-loeh.de>
 stability:	stable
 homepage:	http://www.andres-loeh.de/lhs2tex/
@@ -12,13 +12,7 @@
 category:       Development, Language
 build-type:     Custom
 
-flag splitBase
-  description:	Choose the new smaller, split-up base package.
-
 executable lhs2TeX
   main-is:	Main.lhs
-  if flag(splitBase)
-    build-depends:	base >= 3 && < 5, regex-compat, mtl, filepath, directory, process, utf8-string, extensible-exceptions
-  else
-    build-depends:	base < 3, regex-compat, mtl, filepath, utf8-string
+  build-depends:	base >= 4.2 && < 5, regex-compat, mtl, filepath, directory, process, extensible-exceptions
 
