diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,13 @@
+# hpqtypes-1.5.0 (2016-06-21)
+* remove orphan MonadDB instances
+* turn ConnectionSource into indexed datatype
+* remove Binary wrapper and (de)serialize ByteString as bytea
+* use Text instead of ByteString where appropriate
+* use UTF-8 client encoding by default for compatibility with Text
+
+# hpqtypes-1.4.5 (2016-05-30)
+* fix compilation with Cabal 1.24 and GHC 8.0.1
+
 # hpqtypes-1.4.4 (2016-01-19)
 * fix lower bound of base version
 
diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,18 +1,18 @@
 {-# OPTIONS_GHC -Wall #-}
-{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
+{-# LANGUAGE ScopedTypeVariables #-}
 import Control.Monad
 import Data.Char
-
 import Distribution.PackageDescription
 import Distribution.Simple
 import Distribution.Simple.LocalBuildInfo
 import Distribution.Simple.Program
+import Distribution.Simple.Program.Find
 import Distribution.Simple.Setup
 import Distribution.Simple.Utils
 import Distribution.Verbosity
-import System.FilePath
 import System.Directory
 import System.Exit
+import System.FilePath
 
 main :: IO ()
 main = defaultMainWithHooks simpleUserHooks {
@@ -32,9 +32,9 @@
 
 pgconfigProgram :: Program
 pgconfigProgram = (simpleProgram "pgconfig") {
-  programFindLocation = \verbosity -> constOrId $ do
-    pgconfig  <- findProgramLocation verbosity "pgconfig"
-    pg_config <- findProgramLocation verbosity "pg_config"
+  programFindLocation = \verbosity psp -> do
+    pgconfig  <- findProgramOnSearchPath verbosity psp "pgconfig"
+    pg_config <- findProgramOnSearchPath verbosity psp "pg_config"
     return $ pgconfig `mplus` pg_config
 }
 
@@ -60,24 +60,10 @@
   -- run configure to create appropriate pqt_config.h
   res <- rawSystemExitCode verbosity "env" ["./configure"]
   case res of
-    ExitFailure _ -> error "libpqtypes configure failed"
-    _             -> setCurrentDirectory dir
+    ExitFailure _ -> putStrLn "WARNING: configure failed, using static pqt_config.h"
+    _             -> return ()
+  setCurrentDirectory dir
 
 pqTypesDistclean :: Verbosity -> IO ()
 pqTypesDistclean verbosity =
   rawSystemExit verbosity "env" ["make", "--directory=libpqtypes", "distclean"]
-
---------------------
-
--- 'ConstOrId' is a @Cabal-1.16@ vs @Cabal-1.18@ compatibility hack,
--- 'programFindLocation' has a new (unused in this case)
--- parameter. 'ConstOrId' adds this parameter when types say it is
--- mandatory.
-class ConstOrId a b where
-    constOrId :: a -> b
-
-instance ConstOrId a a where
-    constOrId = id
-
-instance ConstOrId a (b -> a) where
-    constOrId = const
diff --git a/hpqtypes.cabal b/hpqtypes.cabal
--- a/hpqtypes.cabal
+++ b/hpqtypes.cabal
@@ -1,5 +1,5 @@
 name:                hpqtypes
-version:             1.4.4
+version:             1.5.0
 synopsis:            Haskell bindings to libpqtypes
 
 description:         Efficient and easy-to-use bindings to (slightly modified)
@@ -27,10 +27,10 @@
 license:             BSD3
 license-file:        LICENSE
 author:              Scrive
-maintainer:          Andrzej Rybczak <andrzej@scrive.com>
+maintainer:          Andrzej Rybczak <andrzej@rybczak.net>
 category:            Database
 build-type:          Custom
-cabal-version:       >= 1.8
+cabal-version:       >= 1.18
 
 extra-source-files: CHANGELOG.md
                   , examples/Catalog.hs
@@ -53,6 +53,7 @@
                   , libpqtypes/missing
                   , libpqtypes/Makefile.am
                   , libpqtypes/aclocal.m4
+                  , libpqtypes/src/pqt_config.h
                   , libpqtypes/src/pqt_config.h.in
                   , libpqtypes/src/libpqtypes-int.h
                   , libpqtypes/src/libpqtypes.h
@@ -79,10 +80,7 @@
                      , Database.PostgreSQL.PQTypes.ToSQL
                      , Database.PostgreSQL.PQTypes.Transaction
                      , Database.PostgreSQL.PQTypes.Class
-                     , Database.PostgreSQL.PQTypes.Class.Instances
-                     , Database.PostgreSQL.PQTypes.Class.Instances.Overlapping
                      , Database.PostgreSQL.PQTypes.Format
-                     , Database.PostgreSQL.PQTypes.Binary
                      , Database.PostgreSQL.PQTypes.Interval
                      , Database.PostgreSQL.PQTypes.Notification
                      , Database.PostgreSQL.PQTypes.SQL
@@ -121,6 +119,7 @@
                      , containers >= 0.4.0.0
                      , exceptions >= 0.6
                      , data-default-class
+                     , text-show
 
   hs-source-dirs:    src
 
@@ -150,6 +149,30 @@
                      , libpqtypes/src/utils.c
                      , libpqtypes/src/varlena.c
 
+  default-language:  Haskell2010
+  default-extensions: BangPatterns
+                    , ConstraintKinds
+                    , DataKinds
+                    , DeriveDataTypeable
+                    , DeriveFunctor
+                    , ExistentialQuantification
+                    , FlexibleContexts
+                    , FlexibleInstances
+                    , ForeignFunctionInterface
+                    , GADTs
+                    , GeneralizedNewtypeDeriving
+                    , MultiParamTypeClasses
+                    , NoImplicitPrelude
+                    , OverloadedStrings
+                    , RankNTypes
+                    , RecordWildCards
+                    , ScopedTypeVariables
+                    , StandaloneDeriving
+                    , TupleSections
+                    , TypeFamilies
+                    , TypeOperators
+                    , UndecidableInstances
+  
 Executable tests
   if flag(tests)
     buildable:       True
@@ -179,6 +202,28 @@
                      , scientific
                      , unordered-containers
                      , vector
+                     , text-show
 
   main-is:           Main.hs
 
+  default-language:  Haskell2010
+  default-extensions: BangPatterns
+                    , DeriveDataTypeable
+                    , DeriveFunctor
+                    , ExistentialQuantification
+                    , FlexibleContexts
+                    , FlexibleInstances
+                    , ForeignFunctionInterface
+                    , GADTs
+                    , GeneralizedNewtypeDeriving
+                    , MultiParamTypeClasses
+                    , NoImplicitPrelude
+                    , OverloadedStrings
+                    , RankNTypes
+                    , RecordWildCards
+                    , ScopedTypeVariables
+                    , StandaloneDeriving
+                    , TupleSections
+                    , TypeFamilies
+                    , TypeOperators
+                    , UndecidableInstances
diff --git a/libpqtypes/src/pqt_config.h b/libpqtypes/src/pqt_config.h
new file mode 100644
--- /dev/null
+++ b/libpqtypes/src/pqt_config.h
@@ -0,0 +1,154 @@
+/* src/pqt_config.h.  Generated from pqt_config.h.in by configure.  */
+/* src/pqt_config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+#define HAVE_ARPA_INET_H 1
+
+/* Define to 1 if you have the `ceil' function. */
+#define HAVE_CEIL 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define to 1 if you have the `floor' function. */
+#define HAVE_FLOOR 1
+
+/* Define if getaddrinfo exists */
+#define HAVE_GETADDRINFO /**/
+
+/* Define to 1 if you have the `hstrerror' function. */
+#define HAVE_HSTRERROR 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the <limits.h> header file. */
+#define HAVE_LIMITS_H 1
+
+/* Define to 1 if you have the <linux/limits.h> header file. */
+#define HAVE_LINUX_LIMITS_H 1
+
+/* Define to 1 if you have the `localtime_r' function. */
+#define HAVE_LOCALTIME_R 1
+
+/* Define to 1 if you have the <math.h> header file. */
+#define HAVE_MATH_H 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the <netdb.h> header file. */
+#define HAVE_NETDB_H 1
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+#define HAVE_NETINET_IN_H 1
+
+/* Define to 1 if you have the `rint' function. */
+#define HAVE_RINT 1
+
+/* Define to 1 if the system has the type `socklen_t'. */
+#define HAVE_SOCKLEN_T 1
+
+/* Define to 1 if you have the <stddef.h> header file. */
+#define HAVE_STDDEF_H 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the `strtol' function. */
+#define HAVE_STRTOL 1
+
+/* Define to 1 if you have the `strtoll' function. */
+#define HAVE_STRTOLL 1
+
+/* Define to 1 if you have the `strtoul' function. */
+#define HAVE_STRTOUL 1
+
+/* Define to 1 if `ss_len' is member of `struct sockaddr_storage'. */
+/* #undef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN */
+
+/* Define to 1 if `tm_gmtoff' is member of `struct tm'. */
+#define HAVE_STRUCT_TM_TM_GMTOFF 1
+
+/* Define to 1 if `tm_zone' is member of `struct tm'. */
+#define HAVE_STRUCT_TM_TM_ZONE 1
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#define HAVE_SYS_SOCKET_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#define HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <time.h> header file. */
+#define HAVE_TIME_H 1
+
+/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
+   `HAVE_STRUCT_TM_TM_ZONE' instead. */
+#define HAVE_TM_ZONE 1
+
+/* Define to 1 if you don't have `tm_zone' but do have the external array
+   `tzname'. */
+/* #undef HAVE_TZNAME */
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to 1 if you have the `vsnprintf' function. */
+#define HAVE_VSNPRINTF 1
+
+/* Name of package */
+#define PACKAGE "libpqtypes"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "libpqtypes@esilo.com"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "libpqtypes"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "libpqtypes 1.5.1"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "libpqtypes"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "1.5.1"
+
+/* Define to 1 if using FSU pthreads */
+/* #undef PTHREAD_FSU */
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define to 1 if architecture requires strict memory alignment */
+/* #undef STRICT_MEMORY_ALIGNMENT */
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+#define TIME_WITH_SYS_TIME 1
+
+/* Define to 1 if your <sys/time.h> declares `struct tm'. */
+/* #undef TM_IN_SYS_TIME */
+
+/* Version number of package */
+#define VERSION "1.5.1"
+
+/* Define to empty if `const' does not conform to ANSI C. */
+/* #undef const */
+
+/* Define to `unsigned' if <sys/types.h> does not define. */
+/* #undef size_t */
diff --git a/src/Data/Monoid/Utils.hs b/src/Data/Monoid/Utils.hs
--- a/src/Data/Monoid/Utils.hs
+++ b/src/Data/Monoid/Utils.hs
@@ -9,6 +9,7 @@
 import Data.List
 import Data.Monoid
 import Data.String
+import Prelude
 
 -- | Generalization of 'intercalate' to arbitrary 'Monoid'.
 mintercalate :: Monoid m => m -> [m] -> m
diff --git a/src/Database/PostgreSQL/PQTypes.hs b/src/Database/PostgreSQL/PQTypes.hs
--- a/src/Database/PostgreSQL/PQTypes.hs
+++ b/src/Database/PostgreSQL/PQTypes.hs
@@ -5,7 +5,8 @@
     Connection
   , ConnectionStats(..)
   , ConnectionSettings(..)
-  , ConnectionSource
+  , ConnectionSourceM
+  , ConnectionSource(..)
   , simpleSource
   , poolSource
   -- Database.PostgreSQL.PQTypes.Internal.Error
@@ -37,7 +38,6 @@
   -- * Other modules
   , module Data.Functor.Identity
   , module Database.PostgreSQL.PQTypes.Array
-  , module Database.PostgreSQL.PQTypes.Binary
   , module Database.PostgreSQL.PQTypes.Class
   , module Database.PostgreSQL.PQTypes.Composite
   , module Database.PostgreSQL.PQTypes.Fold
@@ -60,22 +60,19 @@
 
 import Data.Functor.Identity
 
-import Database.PostgreSQL.PQTypes.Internal.Connection
-import Database.PostgreSQL.PQTypes.Internal.Error
-import Database.PostgreSQL.PQTypes.Internal.Error.Code
-import Database.PostgreSQL.PQTypes.Internal.Exception
-import Database.PostgreSQL.PQTypes.Internal.Monad
-import Database.PostgreSQL.PQTypes.Internal.QueryResult
-
 import Database.PostgreSQL.PQTypes.Array
-import Database.PostgreSQL.PQTypes.Binary
 import Database.PostgreSQL.PQTypes.Class
-import Database.PostgreSQL.PQTypes.Class.Instances ()
 import Database.PostgreSQL.PQTypes.Composite
 import Database.PostgreSQL.PQTypes.Fold
 import Database.PostgreSQL.PQTypes.Format
 import Database.PostgreSQL.PQTypes.FromRow
 import Database.PostgreSQL.PQTypes.FromSQL
+import Database.PostgreSQL.PQTypes.Internal.Connection
+import Database.PostgreSQL.PQTypes.Internal.Error
+import Database.PostgreSQL.PQTypes.Internal.Error.Code
+import Database.PostgreSQL.PQTypes.Internal.Exception
+import Database.PostgreSQL.PQTypes.Internal.Monad
+import Database.PostgreSQL.PQTypes.Internal.QueryResult
 import Database.PostgreSQL.PQTypes.Interval
 import Database.PostgreSQL.PQTypes.JSON
 import Database.PostgreSQL.PQTypes.Notification
@@ -88,3 +85,4 @@
 import Database.PostgreSQL.PQTypes.Transaction.Settings
 import Database.PostgreSQL.PQTypes.Utils
 import Database.PostgreSQL.PQTypes.XML
+
diff --git a/src/Database/PostgreSQL/PQTypes/Array.hs b/src/Database/PostgreSQL/PQTypes/Array.hs
--- a/src/Database/PostgreSQL/PQTypes/Array.hs
+++ b/src/Database/PostgreSQL/PQTypes/Array.hs
@@ -1,6 +1,3 @@
-{-# LANGUAGE BangPatterns, DeriveDataTypeable, DeriveFunctor
-  , FlexibleInstances, RecordWildCards, ScopedTypeVariables
-  , TypeFamilies #-}
 module Database.PostgreSQL.PQTypes.Array (
     -- * Array1
     Array1(..)
@@ -23,6 +20,7 @@
 import Foreign.Marshal.Alloc
 import Foreign.Ptr
 import Foreign.Storable
+import Prelude
 import qualified Control.Exception as E
 import qualified Data.ByteString.Char8 as BS
 import qualified Data.ByteString.Unsafe as BS
@@ -64,9 +62,10 @@
 
 instance ToSQL t => ToSQL (Array1 t) where
   type PQDest (Array1 t) = PGarray
-  toSQL (Array1 arr) allocParam conv = alloca $ \err -> allocParam $ \param ->
+  toSQL (Array1 arr) pa@(ParamAllocator allocParam) conv =
+    alloca $ \err -> allocParam $ \param ->
     putArray1 arr param conv $ \fmt item ->
-      toSQL item allocParam (c_PQputf1 param err fmt)
+      toSQL item pa (c_PQputf1 param err fmt)
         >>= verifyPQTRes err "toSQL (Array1)"
 
 ----------------------------------------
@@ -91,9 +90,10 @@
 
 instance CompositeToSQL t => ToSQL (CompositeArray1 t) where
   type PQDest (CompositeArray1 t) = PGarray
-  toSQL (CompositeArray1 arr) allocParam conv = alloca $ \err -> allocParam $ \param ->
+  toSQL (CompositeArray1 arr) pa@(ParamAllocator allocParam) conv =
+    alloca $ \err -> allocParam $ \param ->
     putArray1 arr param conv $ \fmt item ->
-      toSQL (Composite item) allocParam (c_PQputf1 param err fmt)
+      toSQL (Composite item) pa (c_PQputf1 param err fmt)
         >>= verifyPQTRes err "toSQL (CompositeArray1)"
 
 ----------------------------------------
@@ -110,7 +110,7 @@
           -> IO r
 putArray1 arr param conv putItem = do
   pqFormat0 (undefined::t) `BS.unsafeUseAsCString` (forM_ arr . putItem)
-  put (PGarray {
+  putAsPtr (PGarray {
     pgArrayNDims = 0
   , pgArrayLBound = V.empty
   , pgArrayDims = V.empty
@@ -171,9 +171,10 @@
 
 instance ToSQL t => ToSQL (Array2 t) where
   type PQDest (Array2 t) = PGarray
-  toSQL (Array2 arr) allocParam conv = alloca $ \err -> allocParam $ \param ->
+  toSQL (Array2 arr) pa@(ParamAllocator allocParam) conv =
+    alloca $ \err -> allocParam $ \param ->
     putArray2 arr param conv $ \fmt item ->
-      toSQL item allocParam (c_PQputf1 param err fmt)
+      toSQL item pa (c_PQputf1 param err fmt)
           >>= verifyPQTRes err "toSQL (Array2)"
 
 ----------------------------------------
@@ -198,9 +199,10 @@
 
 instance CompositeToSQL t => ToSQL (CompositeArray2 t) where
   type PQDest (CompositeArray2 t) = PGarray
-  toSQL (CompositeArray2 arr) allocParam conv = alloca $ \err -> allocParam $ \param ->
+  toSQL (CompositeArray2 arr) pa@(ParamAllocator allocParam) conv =
+    alloca $ \err -> allocParam $ \param ->
     putArray2 arr param conv $ \fmt item ->
-      toSQL (Composite item) allocParam (c_PQputf1 param err fmt)
+      toSQL (Composite item) pa (c_PQputf1 param err fmt)
         >>= verifyPQTRes err "toSQL (CompositeArray2)"
 
 ----------------------------------------
@@ -217,7 +219,7 @@
           -> IO r
 putArray2 arr param conv putItem = do
   dims <- pqFormat0 (undefined::t) `BS.unsafeUseAsCString` loop arr 0 0
-  put (PGarray {
+  putAsPtr (PGarray {
     pgArrayNDims = 2
   , pgArrayLBound = V.fromList [1, 1]
   , pgArrayDims = dims
diff --git a/src/Database/PostgreSQL/PQTypes/Binary.hs b/src/Database/PostgreSQL/PQTypes/Binary.hs
deleted file mode 100644
--- a/src/Database/PostgreSQL/PQTypes/Binary.hs
+++ /dev/null
@@ -1,37 +0,0 @@
-{-# LANGUAGE DeriveDataTypeable, DeriveFunctor, FlexibleInstances
-  , RecordWildCards, TypeFamilies #-}
-module Database.PostgreSQL.PQTypes.Binary (
-    Binary(..)
-  , unBinary
-  ) where
-
-import Control.Applicative
-import Data.Typeable
-import qualified Data.ByteString.Char8 as BS
-
-import Database.PostgreSQL.PQTypes.Format
-import Database.PostgreSQL.PQTypes.FromSQL
-import Database.PostgreSQL.PQTypes.Internal.C.Types
-import Database.PostgreSQL.PQTypes.ToSQL
-
--- | Wrapper for (de)serializing underlying type as 'bytea'.
-newtype Binary b = Binary b
-  deriving (Eq, Functor, Ord, Show, Typeable)
-
--- | Extract underlying value.
-unBinary :: Binary b -> b
-unBinary (Binary b) = b
-
-instance PQFormat (Binary BS.ByteString) where
-  pqFormat = const $ BS.pack "%bytea"
-
-instance FromSQL (Binary BS.ByteString) where
-  type PQBase (Binary BS.ByteString) = PGbytea
-  -- use handler for ByteStringS for convenience
-  fromSQL mbase = Binary <$> fromSQL mbase
-
-instance ToSQL (Binary BS.ByteString) where
-  type PQDest (Binary BS.ByteString) = PGbytea
-  -- use handler for ByteStringS as it properly handles
-  -- the case when underlying ByteString pointer is NULL.
-  toSQL (Binary bs) = toSQL bs
diff --git a/src/Database/PostgreSQL/PQTypes/Class.hs b/src/Database/PostgreSQL/PQTypes/Class.hs
--- a/src/Database/PostgreSQL/PQTypes/Class.hs
+++ b/src/Database/PostgreSQL/PQTypes/Class.hs
@@ -1,15 +1,20 @@
+{-# LANGUAGE OverlappingInstances #-}
+{-# OPTIONS_GHC -fno-warn-deprecated-flags #-}
 module Database.PostgreSQL.PQTypes.Class (
     MonadDB(..)
   ) where
 
 import Control.Applicative
+import Control.Monad.Trans
+import Control.Monad.Trans.Control
+import Prelude
 
 import Database.PostgreSQL.PQTypes.FromRow
 import Database.PostgreSQL.PQTypes.Internal.Connection
 import Database.PostgreSQL.PQTypes.Internal.Notification
 import Database.PostgreSQL.PQTypes.Internal.QueryResult
-import Database.PostgreSQL.PQTypes.Transaction.Settings
 import Database.PostgreSQL.PQTypes.SQL.Class
+import Database.PostgreSQL.PQTypes.Transaction.Settings
 
 class (Applicative m, Monad m) => MonadDB m where
   -- | Run SQL query and return number of affected/returned rows. Note that
@@ -59,3 +64,25 @@
   -- do not want the connection in child thread to be shared with
   -- the parent one.
   withNewConnection :: m a -> m a
+
+-- | Generic, overlapping instance.
+instance (
+    Applicative (t m)
+  , Monad (t m)
+  , MonadTrans t
+  , MonadTransControl t
+  , MonadDB m
+  ) => MonadDB (t m) where
+    runQuery = lift . runQuery
+    getLastQuery = lift getLastQuery
+    getConnectionStats = lift getConnectionStats
+    getQueryResult = lift getQueryResult
+    clearQueryResult = lift clearQueryResult
+    getTransactionSettings = lift getTransactionSettings
+    setTransactionSettings = lift . setTransactionSettings
+    getNotification = lift . getNotification
+    withNewConnection m = controlT $ \run -> withNewConnection (run m)
+
+controlT :: (MonadTransControl t, Monad (t m), Monad m)
+         => (Run t -> m (StT t a)) -> t m a
+controlT f = liftWith f >>= restoreT . return
diff --git a/src/Database/PostgreSQL/PQTypes/Class/Instances.hs b/src/Database/PostgreSQL/PQTypes/Class/Instances.hs
deleted file mode 100644
--- a/src/Database/PostgreSQL/PQTypes/Class/Instances.hs
+++ /dev/null
@@ -1,140 +0,0 @@
-{-# OPTIONS_GHC -fno-warn-orphans #-}
-{-# LANGUAGE FlexibleContexts, UndecidableInstances #-}
-module Database.PostgreSQL.PQTypes.Class.Instances where
-
-import Control.Monad.Trans
-import Control.Monad.Trans.Error
-import Control.Monad.Trans.Identity
-import Control.Monad.Trans.List
-import Control.Monad.Trans.Maybe
-import Control.Monad.Trans.Reader
-import Data.Monoid
-import qualified Control.Monad.Trans.RWS.Lazy as L
-import qualified Control.Monad.Trans.RWS.Strict as S
-import qualified Control.Monad.Trans.State.Lazy as L
-import qualified Control.Monad.Trans.State.Strict as S
-import qualified Control.Monad.Trans.Writer.Lazy as L
-import qualified Control.Monad.Trans.Writer.Strict as S
-
-import Database.PostgreSQL.PQTypes.Class
-
-instance (Error e, MonadDB m) => MonadDB (ErrorT e m) where
-  runQuery = lift . runQuery
-  getLastQuery = lift getLastQuery
-  getConnectionStats = lift getConnectionStats
-  getQueryResult = lift getQueryResult
-  clearQueryResult = lift clearQueryResult
-  getTransactionSettings = lift getTransactionSettings
-  setTransactionSettings = lift . setTransactionSettings
-  getNotification = lift . getNotification
-  withNewConnection = mapErrorT withNewConnection
-
-instance MonadDB m => MonadDB (IdentityT m) where
-  runQuery = lift . runQuery
-  getLastQuery = lift getLastQuery
-  getConnectionStats = lift getConnectionStats
-  getQueryResult = lift getQueryResult
-  clearQueryResult = lift clearQueryResult
-  getTransactionSettings = lift getTransactionSettings
-  setTransactionSettings = lift . setTransactionSettings
-  getNotification = lift . getNotification
-  withNewConnection = mapIdentityT withNewConnection
-
-instance MonadDB m => MonadDB (ListT m) where
-  runQuery = lift . runQuery
-  getLastQuery = lift getLastQuery
-  getConnectionStats = lift getConnectionStats
-  getQueryResult = lift getQueryResult
-  clearQueryResult = lift clearQueryResult
-  getTransactionSettings = lift getTransactionSettings
-  setTransactionSettings = lift . setTransactionSettings
-  getNotification = lift . getNotification
-  withNewConnection = mapListT withNewConnection
-
-instance MonadDB m => MonadDB (MaybeT m) where
-  runQuery = lift . runQuery
-  getLastQuery = lift getLastQuery
-  getConnectionStats = lift getConnectionStats
-  getQueryResult = lift getQueryResult
-  clearQueryResult = lift clearQueryResult
-  getTransactionSettings = lift getTransactionSettings
-  setTransactionSettings = lift . setTransactionSettings
-  getNotification = lift . getNotification
-  withNewConnection = mapMaybeT withNewConnection
-
-instance (Monoid w, MonadDB m) => MonadDB (L.RWST r w s m) where
-  runQuery = lift . runQuery
-  getLastQuery = lift getLastQuery
-  getConnectionStats = lift getConnectionStats
-  getQueryResult = lift getQueryResult
-  clearQueryResult = lift clearQueryResult
-  getTransactionSettings = lift getTransactionSettings
-  setTransactionSettings = lift . setTransactionSettings
-  getNotification = lift . getNotification
-  withNewConnection = L.mapRWST withNewConnection
-
-instance (Monoid w, MonadDB m) => MonadDB (S.RWST r w s m) where
-  runQuery = lift . runQuery
-  getLastQuery = lift getLastQuery
-  getConnectionStats = lift getConnectionStats
-  getQueryResult = lift getQueryResult
-  clearQueryResult = lift clearQueryResult
-  getTransactionSettings = lift getTransactionSettings
-  setTransactionSettings = lift . setTransactionSettings
-  getNotification = lift . getNotification
-  withNewConnection = S.mapRWST withNewConnection
-
-instance MonadDB m => MonadDB (ReaderT r m) where
-  runQuery = lift . runQuery
-  getLastQuery = lift getLastQuery
-  getConnectionStats = lift getConnectionStats
-  getQueryResult = lift getQueryResult
-  clearQueryResult = lift clearQueryResult
-  getTransactionSettings = lift getTransactionSettings
-  setTransactionSettings = lift . setTransactionSettings
-  getNotification = lift . getNotification
-  withNewConnection = mapReaderT withNewConnection
-
-instance MonadDB m => MonadDB (L.StateT s m) where
-  runQuery = lift . runQuery
-  getLastQuery = lift getLastQuery
-  getConnectionStats = lift getConnectionStats
-  getQueryResult = lift getQueryResult
-  clearQueryResult = lift clearQueryResult
-  getTransactionSettings = lift getTransactionSettings
-  setTransactionSettings = lift . setTransactionSettings
-  getNotification = lift . getNotification
-  withNewConnection = L.mapStateT withNewConnection
-
-instance MonadDB m => MonadDB (S.StateT s m) where
-  runQuery = lift . runQuery
-  getLastQuery = lift getLastQuery
-  getConnectionStats = lift getConnectionStats
-  getQueryResult = lift getQueryResult
-  clearQueryResult = lift clearQueryResult
-  getTransactionSettings = lift getTransactionSettings
-  setTransactionSettings = lift . setTransactionSettings
-  getNotification = lift . getNotification
-  withNewConnection = S.mapStateT withNewConnection
-
-instance (Monoid w, MonadDB m) => MonadDB (L.WriterT w m) where
-  runQuery = lift . runQuery
-  getLastQuery = lift getLastQuery
-  getConnectionStats = lift getConnectionStats
-  getQueryResult = lift getQueryResult
-  clearQueryResult = lift clearQueryResult
-  getTransactionSettings = lift getTransactionSettings
-  setTransactionSettings = lift . setTransactionSettings
-  getNotification = lift . getNotification
-  withNewConnection = L.mapWriterT withNewConnection
-
-instance (Monoid w, MonadDB m) => MonadDB (S.WriterT w m) where
-  runQuery = lift . runQuery
-  getLastQuery = lift getLastQuery
-  getConnectionStats = lift getConnectionStats
-  getQueryResult = lift getQueryResult
-  clearQueryResult = lift clearQueryResult
-  getTransactionSettings = lift getTransactionSettings
-  setTransactionSettings = lift . setTransactionSettings
-  getNotification = lift . getNotification
-  withNewConnection = S.mapWriterT withNewConnection
diff --git a/src/Database/PostgreSQL/PQTypes/Class/Instances/Overlapping.hs b/src/Database/PostgreSQL/PQTypes/Class/Instances/Overlapping.hs
deleted file mode 100644
--- a/src/Database/PostgreSQL/PQTypes/Class/Instances/Overlapping.hs
+++ /dev/null
@@ -1,35 +0,0 @@
-{-# OPTIONS_GHC -fno-warn-orphans #-}
-{-# LANGUAGE FlexibleContexts, FlexibleInstances, OverlappingInstances
-  , RankNTypes, UndecidableInstances #-}
--- | Definition of generic 'MonadDB' instance which works for
--- any transformer with 'MonadTrans' and 'MonadTransControl'
--- instances. Quite convenient, but not imported by default
--- due to OverlappingInstances requirement.
-module Database.PostgreSQL.PQTypes.Class.Instances.Overlapping () where
-
-import Control.Applicative
-import Control.Monad.Trans
-import Control.Monad.Trans.Control
-import Database.PostgreSQL.PQTypes.Class
-
-instance (
-    Applicative (t m)
-  , Monad (t m)
-  , MonadTrans t
-  , MonadTransControl t
-  , MonadDB m
-  ) => MonadDB (t m) where
-    runQuery = lift . runQuery
-    getLastQuery = lift getLastQuery
-    getConnectionStats = lift getConnectionStats
-    getQueryResult = lift getQueryResult
-    clearQueryResult = lift clearQueryResult
-    getTransactionSettings = lift getTransactionSettings
-    setTransactionSettings = lift . setTransactionSettings
-    getNotification = lift . getNotification
-    withNewConnection m = controlT $ \run ->
-      withNewConnection (run m)
-
-controlT :: (MonadTransControl t, Monad (t m), Monad m)
-         => (Run t -> m (StT t a)) -> t m a
-controlT f = liftWith f >>= restoreT . return
diff --git a/src/Database/PostgreSQL/PQTypes/Composite.hs b/src/Database/PostgreSQL/PQTypes/Composite.hs
--- a/src/Database/PostgreSQL/PQTypes/Composite.hs
+++ b/src/Database/PostgreSQL/PQTypes/Composite.hs
@@ -1,5 +1,3 @@
-{-# LANGUAGE DeriveDataTypeable, DeriveFunctor, FlexibleContexts
-  , ScopedTypeVariables, TypeFamilies #-}
 module Database.PostgreSQL.PQTypes.Composite (
     Composite(..)
   , unComposite
@@ -11,11 +9,12 @@
 import Control.Applicative
 import Data.Typeable
 import Foreign.Ptr
+import Prelude
 import qualified Control.Exception as E
 
+import Database.PostgreSQL.PQTypes.Format
 import Database.PostgreSQL.PQTypes.FromRow
 import Database.PostgreSQL.PQTypes.FromSQL
-import Database.PostgreSQL.PQTypes.Format
 import Database.PostgreSQL.PQTypes.Internal.C.Interface
 import Database.PostgreSQL.PQTypes.Internal.C.Types
 import Database.PostgreSQL.PQTypes.Internal.Utils
@@ -60,6 +59,7 @@
 
 instance CompositeToSQL t => ToSQL (Composite t) where
   type PQDest (Composite t) = PGparam
-  toSQL (Composite comp) allocParam conv = allocParam $ \param -> do
-    toRow' (fromComposite comp) allocParam param
-    conv param
+  toSQL (Composite comp) pa@(ParamAllocator allocParam) conv =
+    allocParam $ \param -> do
+      toRow' (fromComposite comp) pa param
+      conv param
diff --git a/src/Database/PostgreSQL/PQTypes/Fold.hs b/src/Database/PostgreSQL/PQTypes/Fold.hs
--- a/src/Database/PostgreSQL/PQTypes/Fold.hs
+++ b/src/Database/PostgreSQL/PQTypes/Fold.hs
@@ -10,6 +10,7 @@
 
 import Control.Applicative
 import Control.Monad.Catch
+import Prelude
 import qualified Data.Foldable as F
 
 import Database.PostgreSQL.PQTypes.Class
diff --git a/src/Database/PostgreSQL/PQTypes/Format.hs b/src/Database/PostgreSQL/PQTypes/Format.hs
--- a/src/Database/PostgreSQL/PQTypes/Format.hs
+++ b/src/Database/PostgreSQL/PQTypes/Format.hs
@@ -1,15 +1,14 @@
-{-# LANGUAGE DeriveDataTypeable, FlexibleInstances, ScopedTypeVariables
-  , TypeOperators #-}
 module Database.PostgreSQL.PQTypes.Format (
     PQFormat(..)
   , (:*:)(..)
   ) where
 
-import Data.Int
 import Data.Functor.Identity
+import Data.Int
 import Data.Time
 import Data.Typeable
 import Data.Word
+import Prelude
 import qualified Data.ByteString.Char8 as BS
 import qualified Data.ByteString.Lazy.Char8 as BSL
 import qualified Data.Text as T
@@ -85,17 +84,19 @@
 instance PQFormat String where
   pqFormat = const $ BS.pack "%btext"
 
-instance PQFormat BS.ByteString where
-  pqFormat = const $ BS.pack "%btext"
-
-instance PQFormat BSL.ByteString where
-  pqFormat = const $ BS.pack "%btext"
-
 instance PQFormat T.Text where
   pqFormat = const $ BS.pack "%btext"
 
 instance PQFormat TL.Text where
   pqFormat = const $ BS.pack "%btext"
+
+-- BYTEA
+
+instance PQFormat BS.ByteString where
+  pqFormat = const $ BS.pack "%bytea"
+
+instance PQFormat BSL.ByteString where
+  pqFormat = const $ BS.pack "%bytea"
 
 -- DATE
 
diff --git a/src/Database/PostgreSQL/PQTypes/FromRow.hs b/src/Database/PostgreSQL/PQTypes/FromRow.hs
--- a/src/Database/PostgreSQL/PQTypes/FromRow.hs
+++ b/src/Database/PostgreSQL/PQTypes/FromRow.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE FlexibleInstances, ScopedTypeVariables, TypeOperators #-}
 module Database.PostgreSQL.PQTypes.FromRow (
     FromRow(..)
   , fromRow'
@@ -8,8 +7,9 @@
 import Data.Functor.Identity
 import Foreign.C
 import Foreign.Marshal.Alloc
-import Foreign.Storable
 import Foreign.Ptr
+import Foreign.Storable
+import Prelude
 import qualified Control.Exception as E
 import qualified Data.ByteString.Unsafe as BS
 
diff --git a/src/Database/PostgreSQL/PQTypes/FromSQL.hs b/src/Database/PostgreSQL/PQTypes/FromSQL.hs
--- a/src/Database/PostgreSQL/PQTypes/FromSQL.hs
+++ b/src/Database/PostgreSQL/PQTypes/FromSQL.hs
@@ -1,5 +1,3 @@
-{-# LANGUAGE BangPatterns, FlexibleContexts, FlexibleInstances
-  , RecordWildCards, ScopedTypeVariables, TypeFamilies #-}
 module Database.PostgreSQL.PQTypes.FromSQL (
     FromSQL(..)
   ) where
@@ -12,6 +10,7 @@
 import Data.Word
 import Foreign.C
 import Foreign.Storable
+import Prelude
 import qualified Control.Exception as E
 import qualified Data.ByteString.Char8 as BS
 import qualified Data.ByteString.Lazy.Char8 as BSL
@@ -80,15 +79,6 @@
 
 -- VARIABLE-LENGTH CHARACTER TYPES
 
-instance FromSQL BS.ByteString where
-  type PQBase BS.ByteString = PGbytea
-  fromSQL Nothing = unexpectedNULL
-  fromSQL (Just bytea) = BS.packCStringLen $ byteaToCStringLen bytea
-
-instance FromSQL BSL.ByteString where
-  type PQBase BSL.ByteString = PGbytea
-  fromSQL = fmap BSL.fromStrict . fromSQL
-
 -- | Assumes that source C string is UTF-8, so if you are working
 -- with a different encoding, you should not rely on this instance.
 instance FromSQL T.Text where
@@ -106,6 +96,17 @@
 instance FromSQL String where
   type PQBase String = PGbytea
   fromSQL mbytea = T.unpack <$> fromSQL mbytea
+
+-- BYTEA
+
+instance FromSQL BS.ByteString where
+  type PQBase BS.ByteString = PGbytea
+  fromSQL Nothing = unexpectedNULL
+  fromSQL (Just bytea) = BS.packCStringLen $ byteaToCStringLen bytea
+
+instance FromSQL BSL.ByteString where
+  type PQBase BSL.ByteString = PGbytea
+  fromSQL = fmap BSL.fromStrict . fromSQL
 
 -- DATE
 
diff --git a/src/Database/PostgreSQL/PQTypes/Internal/C/Get.hs b/src/Database/PostgreSQL/PQTypes/Internal/C/Get.hs
--- a/src/Database/PostgreSQL/PQTypes/Internal/C/Get.hs
+++ b/src/Database/PostgreSQL/PQTypes/Internal/C/Get.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE ForeignFunctionInterface #-}
 -- | Exports a set of FFI-imported PQgetf functions with different arities
 -- (PQgetf is a variadic function and there is no way to import such
 -- functions with FFI in their most generic form).
@@ -6,6 +5,7 @@
 
 import Foreign.C
 import Foreign.Ptr
+import Prelude
 
 import Database.PostgreSQL.PQTypes.Internal.C.Types
 
diff --git a/src/Database/PostgreSQL/PQTypes/Internal/C/Interface.hs b/src/Database/PostgreSQL/PQTypes/Internal/C/Interface.hs
--- a/src/Database/PostgreSQL/PQTypes/Internal/C/Interface.hs
+++ b/src/Database/PostgreSQL/PQTypes/Internal/C/Interface.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE ForeignFunctionInterface #-}
 -- | Exports a set of FFI-imported libpq/libpqtypes functions.
 module Database.PostgreSQL.PQTypes.Internal.C.Interface (
   -- * libpq imports
@@ -34,6 +33,7 @@
 import Foreign.ForeignPtr
 import Foreign.Ptr
 import Foreign.Storable
+import Prelude
 import System.Posix.Types
 import qualified Control.Exception as E
 
diff --git a/src/Database/PostgreSQL/PQTypes/Internal/C/Put.hs b/src/Database/PostgreSQL/PQTypes/Internal/C/Put.hs
--- a/src/Database/PostgreSQL/PQTypes/Internal/C/Put.hs
+++ b/src/Database/PostgreSQL/PQTypes/Internal/C/Put.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE ForeignFunctionInterface #-}
 -- | Exports a set of FFI-imported PQputf functions with different arities
 -- (PQputf is a variadic function and there is no way to import such
 -- functions with FFI in their most generic form).
@@ -6,6 +5,7 @@
 
 import Foreign.C
 import Foreign.Ptr
+import Prelude
 
 import Database.PostgreSQL.PQTypes.Internal.C.Types
 
diff --git a/src/Database/PostgreSQL/PQTypes/Internal/C/Types.hsc b/src/Database/PostgreSQL/PQTypes/Internal/C/Types.hsc
--- a/src/Database/PostgreSQL/PQTypes/Internal/C/Types.hsc
+++ b/src/Database/PostgreSQL/PQTypes/Internal/C/Types.hsc
@@ -1,4 +1,3 @@
-{-# LANGUAGE EmptyDataDecls, RecordWildCards #-}
 -- | Mappings of types used by libpq/libpqtypes to Haskell ADTs.
 module Database.PostgreSQL.PQTypes.Internal.C.Types (
     PGconn
@@ -39,8 +38,9 @@
 import Foreign.Marshal.Array
 import Foreign.Ptr
 import Foreign.Storable
-import qualified Data.Vector.Storable as V
+import Prelude
 import qualified Data.ByteString as BS
+import qualified Data.Vector.Storable as V
 
 #let alignment t = "%lu", (unsigned long)offsetof(struct {char x__; t (y__);}, y__)
 
diff --git a/src/Database/PostgreSQL/PQTypes/Internal/Composite.hs b/src/Database/PostgreSQL/PQTypes/Internal/Composite.hs
--- a/src/Database/PostgreSQL/PQTypes/Internal/Composite.hs
+++ b/src/Database/PostgreSQL/PQTypes/Internal/Composite.hs
@@ -2,22 +2,23 @@
     registerComposites
   ) where
 
-import Foreign.ForeignPtr.Safe
+import Foreign.ForeignPtr
 import Foreign.ForeignPtr.Unsafe
 import Foreign.Marshal.Alloc
 import Foreign.Marshal.Array
 import Foreign.Ptr
-import qualified Data.ByteString as BS
+import Prelude
+import qualified Data.Text as T
 
 import Database.PostgreSQL.PQTypes.Internal.C.Interface
 import Database.PostgreSQL.PQTypes.Internal.C.Types
 import Database.PostgreSQL.PQTypes.Internal.Utils
 
 -- | Register a list of composite types.
-registerComposites :: Ptr PGconn -> [BS.ByteString] -> IO ()
+registerComposites :: Ptr PGconn -> [T.Text] -> IO ()
 registerComposites _ [] = return ()
 registerComposites conn names = do
-  cnames <- mapM bsToCString names
+  cnames <- mapM textToCString names
   withArray (map nameToTypeRep cnames) $ \typereps -> alloca $ \err -> do
     let len = fromIntegral $ length cnames
     c_PQregisterTypes conn err c_PQT_COMPOSITE typereps len 0
diff --git a/src/Database/PostgreSQL/PQTypes/Internal/Connection.hs b/src/Database/PostgreSQL/PQTypes/Internal/Connection.hs
--- a/src/Database/PostgreSQL/PQTypes/Internal/Connection.hs
+++ b/src/Database/PostgreSQL/PQTypes/Internal/Connection.hs
@@ -1,5 +1,3 @@
-{-# LANGUAGE FlexibleContexts, RankNTypes, RecordWildCards
-  , TupleSections #-}
 module Database.PostgreSQL.PQTypes.Internal.Connection (
     Connection(..)
   , ConnectionData(..)
@@ -7,6 +5,7 @@
   , ConnectionStats(..)
   , ConnectionSettings(..)
   , def
+  , ConnectionSourceM(..)
   , ConnectionSource(..)
   , simpleSource
   , poolSource
@@ -26,9 +25,13 @@
 import Foreign.ForeignPtr
 import Foreign.Ptr
 import Foreign.Storable
+import GHC.Exts
+import Prelude
 import qualified Control.Exception as E
 import qualified Data.ByteString as BS
 import qualified Data.Foldable as F
+import qualified Data.Text as T
+import qualified Data.Text.Encoding as T
 
 import Database.PostgreSQL.PQTypes.Internal.C.Interface
 import Database.PostgreSQL.PQTypes.Internal.C.Types
@@ -38,19 +41,21 @@
 
 data ConnectionSettings = ConnectionSettings {
 -- | Connection info string.
-  csConnInfo       :: !BS.ByteString
+  csConnInfo       :: !T.Text
 -- | Client-side encoding. If set to 'Nothing', database encoding is used.
-, csClientEncoding :: !(Maybe BS.ByteString)
+, csClientEncoding :: !(Maybe T.Text)
 -- | A list of composite types to register. In order to be able to
 -- (de)serialize specific composite types, you need to register them.
-, csComposites     :: ![BS.ByteString]
+, csComposites     :: ![T.Text]
 } deriving (Eq, Ord, Show)
 
--- | Default connection settings.
+-- | Default connection settings. Note that all strings sent to PostgreSQL by
+-- the library are encoded as UTF-8, so don't alter client encoding unless you
+-- know what you're doing.
 instance Default ConnectionSettings where
   def = ConnectionSettings {
-    csConnInfo = BS.empty
-  , csClientEncoding = Nothing
+    csConnInfo = T.empty
+  , csClientEncoding = Just "UTF-8"
   , csComposites = []
   }
 
@@ -92,49 +97,58 @@
   unConnection :: MVar (Maybe ConnectionData)
 }
 
-withConnectionData :: Connection
-                   -> String
-                   -> (ConnectionData -> IO (ConnectionData, r))
-                   -> IO r
+withConnectionData
+  :: Connection
+  -> String
+  -> (ConnectionData -> IO (ConnectionData, r))
+  -> IO r
 withConnectionData (Connection mvc) fname f =
   modifyMVar mvc $ \mc -> case mc of
     Nothing -> hpqTypesError $ fname ++ ": no connection"
     Just cd -> first Just <$> f cd
 
 -- | Database connection supplier.
-newtype ConnectionSource = ConnectionSource {
-  withConnection :: (MonadBase IO m, MonadMask m) => (Connection -> m a) -> m a
+newtype ConnectionSourceM m = ConnectionSourceM {
+  withConnection :: forall r. (Connection -> m r) -> m r
 }
 
+-- | Wrapper for a polymorphic connection source.
+newtype ConnectionSource (cs :: [(* -> *) -> Constraint]) = ConnectionSource {
+  unConnectionSource :: forall m. MkConstraint m cs => ConnectionSourceM m
+}
+
 -- | Default connection supplier. It estabilishes new
 -- database connection each time 'withConnection' is called.
-simpleSource :: ConnectionSettings -> ConnectionSource
-simpleSource cs = ConnectionSource {
+simpleSource
+  :: ConnectionSettings
+  -> ConnectionSource [MonadBase IO, MonadMask]
+simpleSource cs = ConnectionSource $ ConnectionSourceM {
   withConnection = bracket (liftBase $ connect cs) (liftBase . disconnect)
 }
 
 -- | Pooled source. It uses striped pool from resource-pool
 -- package to cache estabilished connections and reuse them.
-poolSource :: ConnectionSettings
-           -> Int -- ^ Stripe count. The number of distinct sub-pools
-           -- to maintain. The smallest acceptable value is 1.
-           -> NominalDiffTime -- ^ Amount of time for which an unused database
-           -- connection is kept open. The smallest acceptable value is 0.5
-           -- seconds.
-           --
-           -- The elapsed time before closing database connection may be
-           -- a little longer than requested, as the reaper thread wakes
-           -- at 1-second intervals.
-           -> Int -- ^ Maximum number of database connections to keep open
-           -- per stripe. The smallest acceptable value is 1.
-           --
-           -- Requests for database connections will block if this limit is
-           -- reached on a single stripe, even if other stripes have idle
-           -- connections available.
-           -> IO ConnectionSource
+poolSource
+  :: ConnectionSettings
+  -> Int -- ^ Stripe count. The number of distinct sub-pools
+  -- to maintain. The smallest acceptable value is 1.
+  -> NominalDiffTime -- ^ Amount of time for which an unused database
+  -- connection is kept open. The smallest acceptable value is 0.5
+  -- seconds.
+  --
+  -- The elapsed time before closing database connection may be
+  -- a little longer than requested, as the reaper thread wakes
+  -- at 1-second intervals.
+  -> Int -- ^ Maximum number of database connections to keep open
+  -- per stripe. The smallest acceptable value is 1.
+  --
+  -- Requests for database connections will block if this limit is
+  -- reached on a single stripe, even if other stripes have idle
+  -- connections available.
+  -> IO (ConnectionSource [MonadBase IO, MonadMask])
 poolSource cs numStripes idleTime maxResources = do
   pool <- createPool (connect cs) disconnect numStripes idleTime maxResources
-  return ConnectionSource {
+  return $ ConnectionSource $ ConnectionSourceM {
     withConnection = withResource' pool . (clearStats >=>)
   }
   where
@@ -156,14 +170,14 @@
 -- Useful if one wants to implement custom connection source.
 connect :: ConnectionSettings -> IO Connection
 connect ConnectionSettings{..} = do
-  fconn <- BS.useAsCString csConnInfo c_PQconnectdb
+  fconn <- BS.useAsCString (T.encodeUtf8 csConnInfo) c_PQconnectdb
   withForeignPtr fconn $ \connPtr -> do
     conn <- peek connPtr
     status <- c_PQstatus conn
     when (status /= c_CONNECTION_OK) $
       throwLibPQError conn "connect"
     F.forM_ csClientEncoding $ \enc -> do
-      res <- BS.useAsCString enc (c_PQsetClientEncoding conn)
+      res <- BS.useAsCString (T.encodeUtf8 enc) (c_PQsetClientEncoding conn)
       when (res == -1) $
         throwLibPQError conn "connect"
     c_PQinitTypes conn
diff --git a/src/Database/PostgreSQL/PQTypes/Internal/Error.hs b/src/Database/PostgreSQL/PQTypes/Internal/Error.hs
--- a/src/Database/PostgreSQL/PQTypes/Internal/Error.hs
+++ b/src/Database/PostgreSQL/PQTypes/Internal/Error.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE DeriveDataTypeable, ExistentialQuantification, StandaloneDeriving #-}
 -- | Definitions of exception types.
 module Database.PostgreSQL.PQTypes.Internal.Error (
     DetailedQueryError(..)
@@ -15,6 +14,7 @@
   ) where
 
 import Data.Typeable
+import Prelude
 import qualified Control.Exception as E
 
 import Database.PostgreSQL.PQTypes.Internal.Error.Code
diff --git a/src/Database/PostgreSQL/PQTypes/Internal/Error/Code.hs b/src/Database/PostgreSQL/PQTypes/Internal/Error/Code.hs
--- a/src/Database/PostgreSQL/PQTypes/Internal/Error/Code.hs
+++ b/src/Database/PostgreSQL/PQTypes/Internal/Error/Code.hs
@@ -1,10 +1,10 @@
-{-# LANGUAGE DeriveDataTypeable #-}
 module Database.PostgreSQL.PQTypes.Internal.Error.Code (
     ErrorCode(..)
   , stringToErrorCode
   ) where
 
 import Data.Typeable
+import Prelude
 
 -- | SQL error code. Reference:
 -- <http://www.postgresql.org/docs/devel/static/errcodes-appendix.html>.
diff --git a/src/Database/PostgreSQL/PQTypes/Internal/Exception.hs b/src/Database/PostgreSQL/PQTypes/Internal/Exception.hs
--- a/src/Database/PostgreSQL/PQTypes/Internal/Exception.hs
+++ b/src/Database/PostgreSQL/PQTypes/Internal/Exception.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE DeriveDataTypeable, ExistentialQuantification, StandaloneDeriving #-}
 -- | Definition of main exception type.
 module Database.PostgreSQL.PQTypes.Internal.Exception (
     DBException(..)
@@ -6,6 +5,7 @@
   ) where
 
 import Data.Typeable
+import Prelude
 import qualified Control.Exception as E
 
 import Database.PostgreSQL.PQTypes.SQL.Class
diff --git a/src/Database/PostgreSQL/PQTypes/Internal/Monad.hs b/src/Database/PostgreSQL/PQTypes/Internal/Monad.hs
--- a/src/Database/PostgreSQL/PQTypes/Internal/Monad.hs
+++ b/src/Database/PostgreSQL/PQTypes/Internal/Monad.hs
@@ -1,8 +1,7 @@
-{-# LANGUAGE FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving
-  , MultiParamTypeClasses, ScopedTypeVariables, TupleSections
-  , TypeFamilies, UndecidableInstances, CPP #-}
+{-# LANGUAGE CPP #-}
 module Database.PostgreSQL.PQTypes.Internal.Monad (
-    DBT(..)
+    DBT_(..)
+  , DBT
   , runDBT
   , mapDBT
   ) where
@@ -17,6 +16,7 @@
 import Control.Monad.Trans.Control
 import Control.Monad.Writer.Class
 import Data.Monoid
+import Prelude
 import qualified Control.Monad.Trans.State.Strict as S
 
 import Database.PostgreSQL.PQTypes.Class
@@ -31,17 +31,23 @@
 import Database.PostgreSQL.PQTypes.Transaction.Settings
 import Database.PostgreSQL.PQTypes.Utils
 
-type InnerDBT = StateT DBState
+type InnerDBT m = StateT (DBState m)
 
 -- | Monad transformer for adding database
 -- interaction capabilities to the underlying monad.
-newtype DBT m a = DBT { unDBT :: InnerDBT m a }
+newtype DBT_ m n a = DBT { unDBT :: InnerDBT m n a }
   deriving (Alternative, Applicative, Functor, Monad, MonadBase b, MonadCatch, MonadIO, MonadMask, MonadPlus, MonadThrow, MonadTrans)
 
+type DBT m = DBT_ m m
+
 -- | Evaluate monadic action with supplied
 -- connection source and transaction settings.
-runDBT :: (MonadBase IO m, MonadMask m)
-       => ConnectionSource -> TransactionSettings -> DBT m a -> m a
+runDBT
+  :: (MonadBase IO m, MonadMask m)
+  => ConnectionSourceM m
+  -> TransactionSettings
+  -> DBT m a
+  -> m a
 runDBT cs ts m = withConnection cs $ \conn -> do
   evalStateT action $ DBState {
     dbConnection = conn
@@ -56,12 +62,16 @@
       else m
 
 -- | Transform the underlying monad.
-mapDBT :: (m (a, DBState) -> n (b, DBState)) -> DBT m a -> DBT n b
-mapDBT f = DBT . mapStateT f . unDBT
+mapDBT
+  :: (DBState n -> DBState m)
+  -> (m (a, DBState m) -> n (b, DBState n))
+  -> DBT m a
+  -> DBT n b
+mapDBT f g m = DBT . StateT $ g . runStateT (unDBT m) . f
 
 ----------------------------------------
 
-instance (MonadBase IO m, MonadMask m) => MonadDB (DBT m) where
+instance (m ~ n, MonadBase IO m, MonadMask m) => MonadDB (DBT_ m n) where
   runQuery sql = DBT . StateT $ liftBase . runQueryIO sql
   getLastQuery = DBT . gets $ dbLastQuery
 
@@ -88,51 +98,51 @@
 
 ----------------------------------------
 
-instance MonadTransControl DBT where
+instance MonadTransControl (DBT_ m) where
 #if MIN_VERSION_monad_control(1,0,0)
-  type StT DBT a = StT InnerDBT a
+  type StT (DBT_ m) a = StT (InnerDBT m) a
   liftWith = defaultLiftWith DBT unDBT
   restoreT = defaultRestoreT DBT
   {-# INLINE liftWith #-}
   {-# INLINE restoreT #-}
 #else
-  newtype StT DBT a = StDBT { unStDBT :: StT InnerDBT a }
+  newtype StT (DBT_ m) a = StDBT { unStDBT :: StT (InnerDBT m) a }
   liftWith = defaultLiftWith DBT unDBT StDBT
   restoreT = defaultRestoreT DBT unStDBT
   {-# INLINE liftWith #-}
   {-# INLINE restoreT #-}
 #endif
 
-instance MonadBaseControl b m => MonadBaseControl b (DBT m) where
+instance (m ~ n, MonadBaseControl b m) => MonadBaseControl b (DBT_ m n) where
 #if MIN_VERSION_monad_control(1,0,0)
-  type StM (DBT m) a = ComposeSt DBT m a
+  type StM (DBT_ m n) a = ComposeSt (DBT_ m) m a
   liftBaseWith = defaultLiftBaseWith
   restoreM     = defaultRestoreM
   {-# INLINE liftBaseWith #-}
   {-# INLINE restoreM #-}
 #else
-  newtype StM (DBT m) a = StMDBT { unStMDBT :: ComposeSt DBT m a }
+  newtype StM (DBT m) a = StMDBT { unStMDBT :: ComposeSt (DBT_ m) m a }
   liftBaseWith = defaultLiftBaseWith StMDBT
   restoreM     = defaultRestoreM unStMDBT
   {-# INLINE liftBaseWith #-}
   {-# INLINE restoreM #-}
 #endif
 
-instance MonadError e m => MonadError e (DBT m) where
+instance (m ~ n, MonadError e m) => MonadError e (DBT_ m n) where
   throwError = lift . throwError
   catchError m h = DBT $ S.liftCatch catchError (unDBT m) (unDBT . h)
 
-instance MonadReader r m => MonadReader r (DBT m) where
+instance (m ~ n, MonadReader r m) => MonadReader r (DBT_ m n) where
   ask = lift ask
-  local f = mapDBT (local f)
+  local f = mapDBT id (local f)
   reader = lift . reader
 
-instance MonadState s m => MonadState s (DBT m) where
+instance (m ~ n, MonadState s m) => MonadState s (DBT_ m n) where
   get = lift get
   put = lift . put
   state = lift . state
 
-instance MonadWriter w m => MonadWriter w (DBT m) where
+instance (m ~ n, MonadWriter w m) => MonadWriter w (DBT_ m n) where
   writer = lift . writer
   tell = lift . tell
   listen = DBT . S.liftListen listen . unDBT
diff --git a/src/Database/PostgreSQL/PQTypes/Internal/Notification.hsc b/src/Database/PostgreSQL/PQTypes/Internal/Notification.hsc
--- a/src/Database/PostgreSQL/PQTypes/Internal/Notification.hsc
+++ b/src/Database/PostgreSQL/PQTypes/Internal/Notification.hsc
@@ -1,5 +1,3 @@
-{-# LANGUAGE DeriveDataTypeable, ForeignFunctionInterface, RecordWildCards
-  , TupleSections #-}
 module Database.PostgreSQL.PQTypes.Internal.Notification (
     Channel(..)
   , Notification(..)
@@ -13,10 +11,13 @@
 import Data.Typeable
 import Foreign.Ptr
 import Foreign.Storable
+import Prelude
 import System.Posix.Types
 import System.Timeout
 import qualified Control.Exception as E
 import qualified Data.ByteString.Char8 as BS
+import qualified Data.Text as T
+import qualified Data.Text.Encoding as T
 
 import Database.PostgreSQL.PQTypes.Internal.C.Interface
 import Database.PostgreSQL.PQTypes.Internal.C.Types
@@ -53,7 +54,7 @@
   -- | Notification channel name.
 , ntChannel :: !Channel
   -- | Notification payload string.
-, ntPayload :: !BS.ByteString
+, ntPayload :: !T.Text
 } deriving (Eq, Ord, Show, Typeable)
 
 instance Storable Notification where
@@ -62,9 +63,9 @@
   peek ptr = do
     ntPID <- return . CPid
       =<< #{peek PGnotify, be_pid} ptr
-    ntChannel <- fmap (Channel . flip rawSQL ()) . BS.packCString
+    ntChannel <- fmap (Channel . flip rawSQL () . T.decodeUtf8) . BS.packCString
       =<< #{peek PGnotify, relname} ptr
-    ntPayload <- BS.packCString
+    ntPayload <- fmap T.decodeUtf8 . BS.packCString
       =<< #{peek PGnotify, extra} ptr
     return Notification{..}
   poke _ _ = error "Storable Notification: poke is not supposed to be used"
@@ -73,7 +74,7 @@
 
 -- | Low-level function that waits for a notification for a given
 -- number of microseconds (it uses 'timeout' function internally).
-getNotificationIO :: DBState -> Int -> IO (Maybe Notification)
+getNotificationIO :: DBState m -> Int -> IO (Maybe Notification)
 getNotificationIO st n = timeout n $ do
   withConnectionData (dbConnection st) fname $ \cd -> fix $ \loop -> do
     let conn = cdPtr cd
diff --git a/src/Database/PostgreSQL/PQTypes/Internal/Query.hs b/src/Database/PostgreSQL/PQTypes/Internal/Query.hs
--- a/src/Database/PostgreSQL/PQTypes/Internal/Query.hs
+++ b/src/Database/PostgreSQL/PQTypes/Internal/Query.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE FlexibleContexts, RecordWildCards #-}
 module Database.PostgreSQL.PQTypes.Internal.Query (
     runQueryIO
   ) where
@@ -6,6 +5,7 @@
 import Control.Applicative
 import Foreign.ForeignPtr
 import Foreign.Ptr
+import Prelude
 import qualified Control.Exception as E
 import qualified Data.ByteString.Char8 as BS
 
@@ -17,15 +17,17 @@
 import Database.PostgreSQL.PQTypes.Internal.Exception
 import Database.PostgreSQL.PQTypes.Internal.QueryResult
 import Database.PostgreSQL.PQTypes.Internal.State
-import Database.PostgreSQL.PQTypes.SQL.Class
 import Database.PostgreSQL.PQTypes.Internal.Utils
+import Database.PostgreSQL.PQTypes.SQL.Class
+import Database.PostgreSQL.PQTypes.ToSQL
 
 -- | Low-level function for running SQL query.
-runQueryIO :: IsSQL sql => sql -> DBState -> IO (Int, DBState)
+runQueryIO :: IsSQL sql => sql -> DBState m -> IO (Int, DBState m)
 runQueryIO sql st = do
   (affected, res) <- withConnectionData (dbConnection st) "runQueryIO" $ \cd -> do
     let ConnectionData{..} = cd
-    (paramCount, res) <- withSQL sql (withPGparam cdPtr) $ \param query -> (,)
+        allocParam = ParamAllocator $ withPGparam cdPtr
+    (paramCount, res) <- withSQL sql allocParam $ \param query -> (,)
       <$> (fromIntegral <$> c_PQparamCount param)
       <*> c_PQparamExec cdPtr nullPtr param query c_RESULT_BINARY
     affected <- withForeignPtr res $ verifyResult cdPtr
diff --git a/src/Database/PostgreSQL/PQTypes/Internal/QueryResult.hs b/src/Database/PostgreSQL/PQTypes/Internal/QueryResult.hs
--- a/src/Database/PostgreSQL/PQTypes/Internal/QueryResult.hs
+++ b/src/Database/PostgreSQL/PQTypes/Internal/QueryResult.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE BangPatterns, ExistentialQuantification #-}
 module Database.PostgreSQL.PQTypes.Internal.QueryResult (
     QueryResult(..)
   , ntuples
@@ -12,6 +11,7 @@
 import Foreign.ForeignPtr
 import Foreign.Marshal.Alloc
 import Foreign.Ptr
+import Prelude
 import System.IO.Unsafe
 import qualified Control.Exception as E
 
diff --git a/src/Database/PostgreSQL/PQTypes/Internal/State.hs b/src/Database/PostgreSQL/PQTypes/Internal/State.hs
--- a/src/Database/PostgreSQL/PQTypes/Internal/State.hs
+++ b/src/Database/PostgreSQL/PQTypes/Internal/State.hs
@@ -1,9 +1,10 @@
 -- | Definition of internal DBT state.
-{-# LANGUAGE RankNTypes #-}
 module Database.PostgreSQL.PQTypes.Internal.State (
     DBState(..)
   ) where
 
+import Prelude
+
 import Database.PostgreSQL.PQTypes.FromRow
 import Database.PostgreSQL.PQTypes.Internal.Connection
 import Database.PostgreSQL.PQTypes.Internal.QueryResult
@@ -11,15 +12,15 @@
 import Database.PostgreSQL.PQTypes.Transaction.Settings
 
 -- | Internal DB state.
-data DBState = DBState {
+data DBState m = DBState {
 -- | Active connection.
   dbConnection          :: !Connection
 -- | Supplied connection source.
-, dbConnectionSource    :: !ConnectionSource
+, dbConnectionSource    :: !(ConnectionSourceM m)
 -- | Current transaction settings.
 , dbTransactionSettings :: !TransactionSettings
 -- | Last SQL query that was executed.
 , dbLastQuery           :: !SomeSQL
 -- | Current query result.
-, dbQueryResult         :: !(FromRow row => Maybe (QueryResult row))
+, dbQueryResult         :: !(forall row. FromRow row => Maybe (QueryResult row))
 }
diff --git a/src/Database/PostgreSQL/PQTypes/Internal/Utils.hs b/src/Database/PostgreSQL/PQTypes/Internal/Utils.hs
--- a/src/Database/PostgreSQL/PQTypes/Internal/Utils.hs
+++ b/src/Database/PostgreSQL/PQTypes/Internal/Utils.hs
@@ -1,11 +1,11 @@
-{-# LANGUAGE RecordWildCards #-}
 module Database.PostgreSQL.PQTypes.Internal.Utils (
-    mread
+    MkConstraint
+  , mread
   , safePeekCString
   , safePeekCString'
   , cStringLenToBytea
   , byteaToCStringLen
-  , bsToCString
+  , textToCString
   , verifyPQTRes
   , withPGparam
   , throwLibPQError
@@ -17,7 +17,6 @@
 
 import Control.Applicative
 import Control.Monad
-import Data.ByteString (ByteString)
 import Data.ByteString.Unsafe
 import Foreign.C
 import Foreign.ForeignPtr
@@ -25,12 +24,20 @@
 import Foreign.Marshal.Utils
 import Foreign.Ptr
 import Foreign.Storable
+import GHC.Exts
+import Prelude
 import qualified Control.Exception as E
+import qualified Data.Text as T
+import qualified Data.Text.Encoding as T
 
 import Database.PostgreSQL.PQTypes.Internal.C.Interface
 import Database.PostgreSQL.PQTypes.Internal.C.Types
 import Database.PostgreSQL.PQTypes.Internal.Error
 
+type family MkConstraint (m :: * -> *) (cs :: [(* -> *) -> Constraint]) :: Constraint where
+  MkConstraint m '[] = ()
+  MkConstraint m (c ': cs) = (c m, MkConstraint m cs)
+
 -- Safely read value.
 mread :: Read a => String -> Maybe a
 mread s = do
@@ -58,9 +65,9 @@
 byteaToCStringLen :: PGbytea -> CStringLen
 byteaToCStringLen PGbytea{..} = (pgByteaData, fromIntegral pgByteaLen)
 
--- | Convert 'ByteString' to C string wrapped by foreign pointer.
-bsToCString :: ByteString -> IO (ForeignPtr CChar)
-bsToCString bs = unsafeUseAsCStringLen bs $ \(cs, len) -> do
+-- | Convert 'Text' to UTF-8 encoded C string wrapped by foreign pointer.
+textToCString :: T.Text -> IO (ForeignPtr CChar)
+textToCString bs = unsafeUseAsCStringLen (T.encodeUtf8 bs) $ \(cs, len) -> do
   fptr <- mallocForeignPtrBytes (len + 1)
   withForeignPtr fptr $ \ptr -> do
     copyBytes ptr cs len
diff --git a/src/Database/PostgreSQL/PQTypes/Interval.hsc b/src/Database/PostgreSQL/PQTypes/Interval.hsc
--- a/src/Database/PostgreSQL/PQTypes/Interval.hsc
+++ b/src/Database/PostgreSQL/PQTypes/Interval.hsc
@@ -1,4 +1,3 @@
-{-# LANGUAGE DeriveDataTypeable, RecordWildCards, TypeFamilies #-}
 module Database.PostgreSQL.PQTypes.Interval (
     Interval(..)
   , iyears
@@ -16,6 +15,7 @@
 import Data.Monoid
 import Data.Typeable
 import Foreign.Storable
+import Prelude
 import qualified Data.ByteString.Char8 as BS
 
 import Database.PostgreSQL.PQTypes.Format
@@ -98,7 +98,7 @@
 
 instance ToSQL Interval where
   type PQDest Interval = Interval
-  toSQL int _ = put int
+  toSQL int _ = putAsPtr int
 
 ----------------------------------------
 
diff --git a/src/Database/PostgreSQL/PQTypes/JSON.hs b/src/Database/PostgreSQL/PQTypes/JSON.hs
--- a/src/Database/PostgreSQL/PQTypes/JSON.hs
+++ b/src/Database/PostgreSQL/PQTypes/JSON.hs
@@ -1,5 +1,3 @@
-{-# LANGUAGE DeriveDataTypeable, DeriveFunctor, FlexibleInstances
-  , RankNTypes, TypeFamilies #-}
 module Database.PostgreSQL.PQTypes.JSON (
     JSON(..)
   , JSONB(..)
@@ -9,6 +7,7 @@
 import Data.Aeson
 import Data.Typeable
 import Foreign.Ptr
+import Prelude
 import qualified Control.Exception as E
 import qualified Data.ByteString.Char8 as BS
 import qualified Data.ByteString.Lazy.Char8 as BSL
diff --git a/src/Database/PostgreSQL/PQTypes/Notification.hs b/src/Database/PostgreSQL/PQTypes/Notification.hs
--- a/src/Database/PostgreSQL/PQTypes/Notification.hs
+++ b/src/Database/PostgreSQL/PQTypes/Notification.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE OverloadedStrings #-}
 module Database.PostgreSQL.PQTypes.Notification (
     Channel(..)
   , Notification(..)
@@ -8,7 +7,8 @@
   , notify
   ) where
 
-import Data.ByteString (ByteString)
+import Data.Text (Text)
+import Prelude
 
 import Data.Monoid.Utils
 import Database.PostgreSQL.PQTypes.Class
@@ -29,6 +29,6 @@
 unlistenAll = runSQL_ "UNLISTEN *"
 
 -- | Generate a notification on a given channel.
-notify :: MonadDB m => Channel -> ByteString -> m ()
+notify :: MonadDB m => Channel -> Text -> m ()
 notify (Channel chan) payload = runQuery_
   $ rawSQL "SELECT pg_notify($1, $2)" (unRawSQL chan, payload)
diff --git a/src/Database/PostgreSQL/PQTypes/SQL.hs b/src/Database/PostgreSQL/PQTypes/SQL.hs
--- a/src/Database/PostgreSQL/PQTypes/SQL.hs
+++ b/src/Database/PostgreSQL/PQTypes/SQL.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE GADTs, Rank2Types, TupleSections #-}
 module Database.PostgreSQL.PQTypes.SQL (
     SQL
   , mkSQL
@@ -12,7 +11,10 @@
 import Data.Monoid
 import Data.String
 import Foreign.Marshal.Alloc
+import Prelude
+import TextShow
 import qualified Data.ByteString.Char8 as BS
+import qualified Data.ByteString.Unsafe as BS
 import qualified Data.Foldable as F
 import qualified Data.Sequence as S
 import qualified Data.Text as T
@@ -26,7 +28,7 @@
 import Database.PostgreSQL.PQTypes.ToSQL
 
 data SqlChunk where
-  SqlString :: !BS.ByteString -> SqlChunk
+  SqlString :: !T.Text -> SqlChunk
   SqlParam  :: forall t. (Show t, ToSQL t) => !t -> SqlChunk
 
 -- | Primary SQL type that supports efficient
@@ -38,39 +40,38 @@
 
 ----------------------------------------
 
--- | Construct 'SQL' from 'String'. The underlying 'ByteString'
--- will be encoded as UTF-8, so if you are working with
--- a different encoding, you should not rely on this instance.
+-- | Construct 'SQL' from 'String'.
 instance IsString SQL where
-  fromString = mkSQL . T.encodeUtf8 . T.pack
+  fromString = mkSQL . T.pack
 
 instance IsSQL SQL where
-  withSQL sql allocParam execute = alloca $ \err -> allocParam $ \param -> do
-    nums <- newMVar (1::Int)
-    query <- BS.concat <$> mapM (f param err nums) (unSQL sql)
-    BS.useAsCString query (execute param)
+  withSQL sql pa@(ParamAllocator allocParam) execute = do
+    alloca $ \err -> allocParam $ \param -> do
+      nums <- newMVar (1::Int)
+      query <- T.concat <$> mapM (f param err nums) (unSQL sql)
+      BS.useAsCString (T.encodeUtf8 query) (execute param)
     where
       f param err nums chunk = case chunk of
         SqlString s -> return s
-        SqlParam v -> toSQL v allocParam $ \base ->
-          BS.useAsCString (pqFormat v) $ \fmt -> do
+        SqlParam v -> toSQL v pa $ \base ->
+          BS.unsafeUseAsCString (pqFormat0 v) $ \fmt -> do
             verifyPQTRes err "withSQL (SQL)" =<< c_PQputf1 param err fmt base
-            modifyMVar nums $ \n -> return . (, BS.pack $ "$" ++ show n) $! n+1
+            modifyMVar nums $ \n -> return . (, "$" <> showt n) $! n+1
 
 instance Monoid SQL where
-  mempty = mkSQL BS.empty
+  mempty = mkSQL T.empty
   SQL a `mappend` SQL b = SQL (a S.>< b)
 
 instance Show SQL where
   showsPrec n sql = ("SQL " ++) . (showsPrec n . concatMap conv . unSQL $ sql)
     where
-      conv (SqlString s) = BS.unpack s
+      conv (SqlString s) = T.unpack s
       conv (SqlParam v) = "<" ++ show v ++ ">"
 
 ----------------------------------------
 
 -- | Convert 'ByteString' to 'SQL'.
-mkSQL :: BS.ByteString -> SQL
+mkSQL :: T.Text -> SQL
 mkSQL = SQL . S.singleton . SqlString
 
 -- | Embed parameter value inside 'SQL'.
@@ -92,5 +93,5 @@
 isSqlEmpty :: SQL -> Bool
 isSqlEmpty (SQL chunks) = getAll $ F.foldMap (All . cmp) chunks
   where
-    cmp (SqlString s) = s == BS.empty
+    cmp (SqlString s) = s == T.empty
     cmp (SqlParam _)  = False
diff --git a/src/Database/PostgreSQL/PQTypes/SQL/Class.hs b/src/Database/PostgreSQL/PQTypes/SQL/Class.hs
--- a/src/Database/PostgreSQL/PQTypes/SQL/Class.hs
+++ b/src/Database/PostgreSQL/PQTypes/SQL/Class.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE ExistentialQuantification, Rank2Types #-}
 module Database.PostgreSQL.PQTypes.SQL.Class (
     SomeSQL(..)
   , IsSQL(..)
@@ -8,6 +7,7 @@
 import Data.String
 import Foreign.C.String
 import Foreign.Ptr
+import Prelude
 
 import Database.PostgreSQL.PQTypes.Internal.C.Types
 import Database.PostgreSQL.PQTypes.ToSQL
diff --git a/src/Database/PostgreSQL/PQTypes/SQL/Raw.hs b/src/Database/PostgreSQL/PQTypes/SQL/Raw.hs
--- a/src/Database/PostgreSQL/PQTypes/SQL/Raw.hs
+++ b/src/Database/PostgreSQL/PQTypes/SQL/Raw.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE FlexibleInstances #-}
 module Database.PostgreSQL.PQTypes.SQL.Raw (
     RawSQL
   , rawSQL
@@ -8,40 +7,40 @@
 import Data.Monoid
 import Data.String
 import Foreign.Marshal.Alloc
+import Prelude
 import qualified Data.ByteString.Char8 as BS
 import qualified Data.Text as T
 import qualified Data.Text.Encoding as T
 
 import Database.PostgreSQL.PQTypes.SQL.Class
 import Database.PostgreSQL.PQTypes.ToRow
+import Database.PostgreSQL.PQTypes.ToSQL
 
 -- | Form of SQL query which is very close to libpqtypes specific
--- representation. Note that, in particular, 'RawSQL' () is
--- isomorphic (modulo bottom) to 'ByteString'.
-data RawSQL row = RawSQL !BS.ByteString !row
+-- representation. Note that, in particular, 'RawSQL' () is isomorphic (modulo
+-- bottom) to 'Text'.
+data RawSQL row = RawSQL !T.Text !row
   deriving (Eq, Ord, Show)
 
 instance (Show row, ToRow row) => IsSQL (RawSQL row) where
-  withSQL (RawSQL query row) allocParam execute = alloca $ \err ->
-    allocParam $ \param -> do
-      toRow row allocParam param err
-      BS.useAsCString query (execute param)
+  withSQL (RawSQL query row) pa@(ParamAllocator allocParam) execute =
+    alloca $ \err -> allocParam $ \param -> do
+      toRow row pa param err
+      BS.useAsCString (T.encodeUtf8 query) (execute param)
 
--- | Construct 'RawSQL' () from 'String'. The underlying 'ByteString'
--- will be encoded as UTF-8, so if you are working with a different
--- encoding, you should not rely on this instance.
+-- | Construct 'RawSQL' () from 'String'.
 instance IsString (RawSQL ()) where
-  fromString = flip RawSQL () . T.encodeUtf8 . T.pack
+  fromString = flip RawSQL () . T.pack
 
 instance Monoid (RawSQL ()) where
-  mempty = rawSQL BS.empty ()
+  mempty = rawSQL T.empty ()
   RawSQL a () `mappend` RawSQL b () = RawSQL (a `mappend` b) ()
-  mconcat xs = RawSQL (BS.concat $ map (\(RawSQL s ()) -> s) xs) ()
+  mconcat xs = RawSQL (T.concat $ map (\(RawSQL s ()) -> s) xs) ()
 
--- | Construct 'RawSQL' from 'ByteString' and a tuple of parameters.
-rawSQL :: (Show row, ToRow row) => BS.ByteString -> row -> RawSQL row
+-- | Construct 'RawSQL' from 'Text' and a tuple of parameters.
+rawSQL :: (Show row, ToRow row) => T.Text -> row -> RawSQL row
 rawSQL = RawSQL
 
 -- | Take query string out of 'RawSQL' ().
-unRawSQL :: RawSQL () -> BS.ByteString
+unRawSQL :: RawSQL () -> T.Text
 unRawSQL (RawSQL s _) = s
diff --git a/src/Database/PostgreSQL/PQTypes/ToRow.hs b/src/Database/PostgreSQL/PQTypes/ToRow.hs
--- a/src/Database/PostgreSQL/PQTypes/ToRow.hs
+++ b/src/Database/PostgreSQL/PQTypes/ToRow.hs
@@ -1,5 +1,3 @@
-{-# LANGUAGE FlexibleInstances, Rank2Types, ScopedTypeVariables
-  , TypeOperators #-}
 module Database.PostgreSQL.PQTypes.ToRow (
     ToRow(..)
   , toRow'
@@ -9,6 +7,7 @@
 import Foreign.C
 import Foreign.Marshal.Alloc
 import Foreign.Ptr
+import Prelude
 import qualified Data.ByteString.Unsafe as BS
 
 import Database.PostgreSQL.PQTypes.Format
diff --git a/src/Database/PostgreSQL/PQTypes/ToSQL.hs b/src/Database/PostgreSQL/PQTypes/ToSQL.hs
--- a/src/Database/PostgreSQL/PQTypes/ToSQL.hs
+++ b/src/Database/PostgreSQL/PQTypes/ToSQL.hs
@@ -1,9 +1,7 @@
-{-# LANGUAGE FlexibleContexts, FlexibleInstances, Rank2Types
-  , RecordWildCards, ScopedTypeVariables, TypeFamilies #-}
 module Database.PostgreSQL.PQTypes.ToSQL (
-    ParamAllocator
+    ParamAllocator(..)
   , ToSQL(..)
-  , put
+  , putAsPtr
   ) where
 
 import Data.ByteString.Unsafe
@@ -15,6 +13,7 @@
 import Foreign.Marshal.Alloc
 import Foreign.Ptr
 import Foreign.Storable
+import Prelude
 import qualified Data.ByteString.Char8 as BS
 import qualified Data.ByteString.Lazy.Char8 as BSL
 import qualified Data.Text as T
@@ -26,7 +25,7 @@
 import Database.PostgreSQL.PQTypes.Internal.Utils
 
 -- | 'alloca'-like producer of 'PGparam' objects.
-type ParamAllocator = forall r. (Ptr PGparam -> IO r) -> IO r
+newtype ParamAllocator = ParamAllocator (forall r. (Ptr PGparam -> IO r) -> IO r)
 
 -- | Class which represents \"from Haskell type
 -- to SQL (libpqtypes) type\" transformation.
@@ -42,8 +41,8 @@
 
 -- | Function that abstracts away common elements of most 'ToSQL'
 -- instance definitions to make them easier to write and less verbose.
-put :: Storable t => t -> (Ptr t -> IO r) -> IO r
-put x conv = alloca $ \ptr -> poke ptr x >> conv ptr
+putAsPtr :: Storable t => t -> (Ptr t -> IO r) -> IO r
+putAsPtr x conv = alloca $ \ptr -> poke ptr x >> conv ptr
 
 -- NULLables
 
@@ -57,27 +56,27 @@
 
 instance ToSQL Int16 where
   type PQDest Int16 = CShort
-  toSQL n _ = put (fromIntegral n)
+  toSQL n _ = putAsPtr (fromIntegral n)
 
 instance ToSQL Int32 where
   type PQDest Int32 = CInt
-  toSQL n _ = put (fromIntegral n)
+  toSQL n _ = putAsPtr (fromIntegral n)
 
 instance ToSQL Int64 where
   type PQDest Int64 = CLLong
-  toSQL n _ = put (fromIntegral n)
+  toSQL n _ = putAsPtr (fromIntegral n)
 
 instance ToSQL Int where
   type PQDest Int = CLLong
-  toSQL n _ = put (fromIntegral n)
+  toSQL n _ = putAsPtr (fromIntegral n)
 
 instance ToSQL Float where
   type PQDest Float = CFloat
-  toSQL n _ = put (realToFrac n)
+  toSQL n _ = putAsPtr (realToFrac n)
 
 instance ToSQL Double where
   type PQDest Double = CDouble
-  toSQL n _ = put (realToFrac n)
+  toSQL n _ = putAsPtr (realToFrac n)
 
 -- CHAR
 
@@ -85,32 +84,14 @@
   type PQDest Char = CChar
   toSQL c _ conv
     | c > '\255' = hpqTypesError $ "toSQL (Char): character " ++ show c ++ " cannot be losslessly converted to CChar"
-    | otherwise = put (castCharToCChar c) conv
+    | otherwise = putAsPtr (castCharToCChar c) conv
 
 instance ToSQL Word8 where
   type PQDest Word8 = CChar
-  toSQL c _ = put (fromIntegral c)
+  toSQL c _ = putAsPtr (fromIntegral c)
 
 -- VARIABLE-LENGTH CHARACTER TYPES
 
-instance ToSQL BS.ByteString where
-  type PQDest BS.ByteString = PGbytea
-  toSQL bs _ conv = unsafeUseAsCStringLen bs $ \cslen ->
-    -- Note: it seems that ByteString can actually store NULL pointer
-    -- inside. This is bad, since NULL pointers are treated by libpqtypes
-    -- as NULL values. To get around that, nullStringCStringLen is used
-    -- (a static pointer to empty string defined on C level). Actually,
-    -- it would be sufficient to pass any non-NULL pointer there, but
-    -- this is much uglier and dangerous.
-    flip put conv . cStringLenToBytea $
-      if fst cslen == nullPtr
-        then nullStringCStringLen
-        else cslen
-
-instance ToSQL BSL.ByteString where
-  type PQDest BSL.ByteString = PGbytea
-  toSQL = toSQL . BSL.toStrict
-
 -- | Encodes underlying C string as UTF-8, so if you are working
 -- with a different encoding, you should not rely on this instance.
 instance ToSQL T.Text where
@@ -129,23 +110,43 @@
   type PQDest String = PGbytea
   toSQL = toSQL . T.pack
 
+-- BYTEA
+
+instance ToSQL BS.ByteString where
+  type PQDest BS.ByteString = PGbytea
+  toSQL bs _ conv = unsafeUseAsCStringLen bs $ \cslen ->
+    -- Note: it seems that ByteString can actually store NULL pointer
+    -- inside. This is bad, since NULL pointers are treated by libpqtypes
+    -- as NULL values. To get around that, nullStringCStringLen is used
+    -- (a static pointer to empty string defined on C level). Actually,
+    -- it would be sufficient to pass any non-NULL pointer there, but
+    -- this is much uglier and dangerous.
+    flip putAsPtr conv . cStringLenToBytea $
+      if fst cslen == nullPtr
+        then nullStringCStringLen
+        else cslen
+
+instance ToSQL BSL.ByteString where
+  type PQDest BSL.ByteString = PGbytea
+  toSQL = toSQL . BSL.toStrict
+
 -- DATE
 
 instance ToSQL Day where
   type PQDest Day = PGdate
-  toSQL day _ = put (dayToPGdate day)
+  toSQL day _ = putAsPtr (dayToPGdate day)
 
 -- TIME
 
 instance ToSQL TimeOfDay where
   type PQDest TimeOfDay = PGtime
-  toSQL tod _ = put (timeOfDayToPGtime tod)
+  toSQL tod _ = putAsPtr (timeOfDayToPGtime tod)
 
 -- TIMESTAMP
 
 instance ToSQL LocalTime where
   type PQDest LocalTime = PGtimestamp
-  toSQL LocalTime{..} _ = put PGtimestamp {
+  toSQL LocalTime{..} _ = putAsPtr PGtimestamp {
     pgTimestampEpoch = 0
   , pgTimestampDate = dayToPGdate localDay
   , pgTimestampTime = timeOfDayToPGtime localTimeOfDay
@@ -155,7 +156,7 @@
 
 instance ToSQL UTCTime where
   type PQDest UTCTime = PGtimestamp
-  toSQL UTCTime{..} _ = put PGtimestamp {
+  toSQL UTCTime{..} _ = putAsPtr PGtimestamp {
     pgTimestampEpoch = 0
   , pgTimestampDate = dayToPGdate utctDay
   , pgTimestampTime = timeOfDayToPGtime $ timeToTimeOfDay utctDayTime
@@ -163,7 +164,7 @@
 
 instance ToSQL ZonedTime where
   type PQDest ZonedTime = PGtimestamp
-  toSQL ZonedTime{..} _ = put PGtimestamp {
+  toSQL ZonedTime{..} _ = putAsPtr PGtimestamp {
     pgTimestampEpoch = 0
   , pgTimestampDate = dayToPGdate $ localDay zonedTimeToLocalTime
   , pgTimestampTime = (timeOfDayToPGtime $ localTimeOfDay zonedTimeToLocalTime) {
@@ -175,8 +176,8 @@
 
 instance ToSQL Bool where
   type PQDest Bool = CInt
-  toSQL True  _ = put 1
-  toSQL False _ = put 0
+  toSQL True  _ = putAsPtr 1
+  toSQL False _ = putAsPtr 0
 
 ----------------------------------------
 
diff --git a/src/Database/PostgreSQL/PQTypes/Transaction.hs b/src/Database/PostgreSQL/PQTypes/Transaction.hs
--- a/src/Database/PostgreSQL/PQTypes/Transaction.hs
+++ b/src/Database/PostgreSQL/PQTypes/Transaction.hs
@@ -1,5 +1,3 @@
-{-# LANGUAGE BangPatterns, FlexibleContexts, OverloadedStrings
-  , Rank2Types, RecordWildCards, ScopedTypeVariables #-}
 module Database.PostgreSQL.PQTypes.Transaction (
     Savepoint(..)
   , withSavepoint
@@ -18,6 +16,7 @@
 import Data.Function
 import Data.String
 import Data.Typeable
+import Prelude
 
 import Data.Monoid.Utils
 import Database.PostgreSQL.PQTypes.Class
diff --git a/src/Database/PostgreSQL/PQTypes/Transaction/Settings.hs b/src/Database/PostgreSQL/PQTypes/Transaction/Settings.hs
--- a/src/Database/PostgreSQL/PQTypes/Transaction/Settings.hs
+++ b/src/Database/PostgreSQL/PQTypes/Transaction/Settings.hs
@@ -1,5 +1,3 @@
-{-# LANGUAGE DeriveDataTypeable, ExistentialQuantification, Rank2Types
-  , RecordWildCards #-}
 module Database.PostgreSQL.PQTypes.Transaction.Settings (
     RestartPredicate(..)
   , TransactionSettings(..)
@@ -10,6 +8,7 @@
 
 import Data.Default.Class
 import Data.Typeable
+import Prelude
 import qualified Control.Exception as E
 
 -- | Predicate that determines whether the transaction has to be restarted.
diff --git a/src/Database/PostgreSQL/PQTypes/Utils.hs b/src/Database/PostgreSQL/PQTypes/Utils.hs
--- a/src/Database/PostgreSQL/PQTypes/Utils.hs
+++ b/src/Database/PostgreSQL/PQTypes/Utils.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE ScopedTypeVariables #-}
 module Database.PostgreSQL.PQTypes.Utils (
     throwDB
   , raw
@@ -15,6 +14,7 @@
 
 import Control.Monad
 import Control.Monad.Catch
+import Prelude
 
 import Database.PostgreSQL.PQTypes.Class
 import Database.PostgreSQL.PQTypes.Internal.Error
diff --git a/src/Database/PostgreSQL/PQTypes/XML.hs b/src/Database/PostgreSQL/PQTypes/XML.hs
--- a/src/Database/PostgreSQL/PQTypes/XML.hs
+++ b/src/Database/PostgreSQL/PQTypes/XML.hs
@@ -1,10 +1,10 @@
-{-# LANGUAGE DeriveDataTypeable, TypeFamilies #-}
 module Database.PostgreSQL.PQTypes.XML (
     XML(..)
   ) where
 
 import Data.Text
 import Data.Typeable
+import Prelude
 import qualified Data.ByteString.Char8 as BSC
 
 import Database.PostgreSQL.PQTypes.Format
diff --git a/test/Main.hs b/test/Main.hs
--- a/test/Main.hs
+++ b/test/Main.hs
@@ -1,5 +1,5 @@
+{-# LANGUAGE CPP #-}
 {-# OPTIONS_GHC -fno-warn-orphans #-}
-{-# LANGUAGE BangPatterns, CPP, DeriveDataTypeable, FlexibleContexts, GeneralizedNewtypeDeriving, MultiParamTypeClasses, OverloadedStrings, RecordWildCards, ScopedTypeVariables, TypeFamilies, TypeOperators, UndecidableInstances #-}
 module Main where
 
 import Control.Applicative
@@ -15,6 +15,7 @@
 import Data.Time
 import Data.Typeable
 import Data.Word
+import Prelude
 import System.Environment
 import System.Exit
 import System.Random
@@ -22,16 +23,16 @@
 import Test.Framework.Providers.HUnit
 import Test.HUnit hiding (Test, assertEqual)
 import Test.QuickCheck
-import Test.QuickCheck.Compat
 import Test.QuickCheck.Gen
+import TextShow
 import qualified Data.ByteString as BS
-import qualified Data.ByteString.Char8 as BSC
 import qualified Data.Text as T
 
 import Data.Monoid.Utils
 import Database.PostgreSQL.PQTypes
 import Prelude.Instances ()
 import Test.QuickCheck.Arbitrary.Instances
+import Test.QuickCheck.Compat
 
 type InnerTestEnv = StateT QCGen (DBT IO)
 
@@ -59,7 +60,7 @@
 
 ----------------------------------------
 
-type TestData = (QCGen, ConnectionSource)
+type TestData = (QCGen, ConnectionSourceM IO)
 
 runTestEnv :: TestData -> TransactionSettings -> TestEnv a -> IO a
 runTestEnv (env, cs) ts m = runDBT cs ts $ evalStateT (unTestEnv m) env
@@ -84,9 +85,6 @@
 instance (Arbitrary a1, Arbitrary a2) => Arbitrary (a1 :*: a2) where
   arbitrary = (:*:) <$> arbitrary <*> arbitrary
 
-instance Arbitrary a => Arbitrary (Binary a) where
-  arbitrary = Binary <$> arbitrary
-
 instance Arbitrary a => Arbitrary (Composite a) where
   arbitrary = Composite <$> arbitrary
 
@@ -319,7 +317,7 @@
         => TestData -> row -> Test
 rowTest td r = testCase ("Putting row of length" <+> show (pqVariables r) <+> "through database works") . runTestEnv td def . runTimes 100 $ do
   row :: row <- randomValue 100
-  let fmt = mintercalate ", " $ map (BSC.pack . ('$' :) . show) [1..pqVariables r]
+  let fmt = mintercalate ", " $ map (T.append "$" . showt) [1..pqVariables r]
   runQuery_ $ rawSQL ("SELECT" <+> fmt) row
   row' <- fetchOne id
   assertEqual "Row doesn't change after getting through database" row row' (==)
@@ -355,7 +353,6 @@
   , nullTest td (u::String)
   , nullTest td (u::BS.ByteString)
   , nullTest td (u::T.Text)
-  , nullTest td (u::Binary BS.ByteString)
   , nullTest td (u::JSON Value)
   , nullTest td (u::JSONB Value)
   , nullTest td (u::XML)
@@ -381,7 +378,6 @@
   , putGetTest td 1000 (u::String0) (==)
   , putGetTest td 1000 (u::BS.ByteString) (==)
   , putGetTest td 1000 (u::T.Text) (==)
-  , putGetTest td 1000 (u::Binary BS.ByteString) (==)
   , putGetTest td 50 (u::JSON Value) (==)
   , putGetTest td 50 (u::JSONB Value) (==)
   , putGetTest td 20 (u::Array1 (JSON Value)) (==)
@@ -414,59 +410,59 @@
   , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0))
   , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString))
   , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day))
-  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, Binary BS.ByteString, Day, Array1 Int32))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day))
+  , rowTest td (u::(Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, Char, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32))
   ]
   where
     u = undefined
 
 ----------------------------------------
 
-createStructures :: ConnectionSource -> IO ()
+createStructures :: ConnectionSourceM IO -> IO ()
 createStructures cs = runDBT cs def $ do
   liftBase . putStrLn $ "Creating structures..."
   runSQL_ "CREATE TABLE test1_ (a INTEGER)"
   runSQL_ "CREATE TYPE simple_ AS (a INTEGER, b DATE)"
   runSQL_ "CREATE TYPE nested_ AS (d DOUBLE PRECISION, s SIMPLE_)"
 
-dropStructures :: ConnectionSource -> IO ()
+dropStructures :: ConnectionSourceM IO -> IO ()
 dropStructures cs = runDBT cs def $ do
   liftBase . putStrLn $ "Dropping structures..."
   runSQL_ "DROP TYPE nested_"
@@ -482,13 +478,13 @@
     exitFailure
 
   let connSettings = def {
-          csConnInfo = BSC.pack $ head args
+          csConnInfo = T.pack $ head args
         , csClientEncoding = Just "latin1"
         }
-      connSource = simpleSource connSettings
+      ConnectionSource connSource = simpleSource connSettings
 
   createStructures connSource
-  connPool <- poolSource (connSettings { csComposites = ["simple_", "nested_"] }) 1 30 16
+  ConnectionSource connPool <- poolSource (connSettings { csComposites = ["simple_", "nested_"] }) 1 30 16
   gen <- newQCGen
   putStrLn $ "PRNG:" <+> show gen
 
