diff --git a/basex-client.cabal b/basex-client.cabal
--- a/basex-client.cabal
+++ b/basex-client.cabal
@@ -2,7 +2,7 @@
 -- documentation, see http://haskell.org/cabal/users-guide/
 
 name:                basex-client
-version:             0.1.0.0
+version:             0.2.0.0
 synopsis:            A BaseX client for Haskell
 description:         A BaseX client library for Haskell that connects to the BaseX server using a socket. BaseX is a light-weight, high-performance and scalable XML Database written in Java.
 license:             MIT
diff --git a/src/AddExample.hs b/src/AddExample.hs
--- a/src/AddExample.hs
+++ b/src/AddExample.hs
@@ -4,8 +4,8 @@
 
 main :: IO ()
 main = withSession "localhost" 1984 "admin" "admin" $ \session -> do
-  execute session "create db database" >>= print
-  add session "world/World.xml" "<x>Hello World!</x>" >>= print
-  add session "Universe.xml" "<x>Hello Universe!</x>" >>= print
-  execute session "xquery /" >>= print
-  execute session "drop db database" >>= print
+  execute "create db database" session >>= print
+  add "world/World.xml" "<x>Hello World!</x>" session >>= print
+  add "Universe.xml" "<x>Hello Universe!</x>" session >>= print
+  execute "xquery /" session >>= print
+  execute "drop db database" session >>= print
diff --git a/src/BaseXClient.hs b/src/BaseXClient.hs
--- a/src/BaseXClient.hs
+++ b/src/BaseXClient.hs
@@ -4,19 +4,19 @@
   module BaseXClient.Session
 ) where
 
-import qualified BaseXClient.Query as Query
 import BaseXClient.Query hiding (info, execute, close, sendCode, exec)
+import qualified BaseXClient.Query as Query
 import BaseXClient.Session hiding (sendInput)
 import Control.Exception
 import Network
 import System.IO
 
 executeQuery = Query.execute
-closeQuery = Query.close
-queryInfo = Query.info
+closeQuery   = Query.close
+queryInfo    = Query.info
 
 withSession :: String -> PortNumber -> String -> String -> (Handle -> IO a) -> IO a
 withSession host port user pass = bracket (connect host port user pass) close
 
 withQuery :: Handle -> String -> (Query -> IO a) -> IO a
-withQuery session q = bracket (query session q) closeQuery
+withQuery session q = bracket (query q session) closeQuery
diff --git a/src/BaseXClient/Query.hs b/src/BaseXClient/Query.hs
--- a/src/BaseXClient/Query.hs
+++ b/src/BaseXClient/Query.hs
@@ -6,20 +6,19 @@
 import Control.Applicative
 import System.IO
 
-data Query = Query {
-    session :: Handle,
-    ident :: String
-  }
-  deriving Show
+data Query = Query
+  { session :: Handle
+  , ident :: String
+  } deriving Show
 
-bind :: Query -> String -> String -> String -> IO String
-bind query name val ty = exec query 3 [name, val, ty]
+bind :: String -> String -> String -> Query -> IO String
+bind name val ty = exec 3 [name, val, ty]
 
-context :: Query -> String -> String -> IO String
-context query val ty = exec query 14 [val, ty]
+context :: String -> String -> Query -> IO String
+context val ty = exec 14 [val, ty]
 
 results :: Query -> IO [String]
-results Query{session, ident} = do
+results Query { session, ident } = do
   writeCode session 4
   writeString session ident
   result <- untilM (ok session) (readString session)
@@ -28,14 +27,14 @@
     else readString session >>= error
 
 execute, info, options, updating, close :: Query -> IO String
-execute = sendCode 5
-info = sendCode 6
-options = sendCode 7
+execute  = sendCode 5
+info     = sendCode 6
+options  = sendCode 7
 updating = sendCode 30
-close = sendCode 2
+close    = sendCode 2
 
 sendCode :: Int -> Query -> IO String
-sendCode code query = exec query code []
+sendCode code = exec code []
 
-exec :: Query -> Int -> [String] -> IO String
-exec Query{session, ident} code strs = Utils.exec session code $ ident : strs
+exec :: Int -> [String] -> Query -> IO String
+exec code args Query { session, ident } = Utils.exec code (ident : args) session
diff --git a/src/BaseXClient/Session.hs b/src/BaseXClient/Session.hs
--- a/src/BaseXClient/Session.hs
+++ b/src/BaseXClient/Session.hs
@@ -1,25 +1,25 @@
 {-# LANGUAGE NamedFieldPuns #-}
-{-# LANGUAGE LambdaCase #-}
 module BaseXClient.Session where
 
-import BaseXClient.Utils
 import BaseXClient.Query (Query(..))
+import BaseXClient.Utils
 import Control.Applicative
-import qualified Data.Digest.Pure.MD5 as MD5
+import Control.Exception
 import Data.ByteString.Lazy.UTF8 (fromString)
+import qualified Data.Digest.Pure.MD5 as MD5
 import Data.List
 import Network
 import System.IO
 
-data Result = Result {
-    content :: String,
-    info :: String
-  }
-  deriving Show
+data Result = Result
+  { content :: String
+  , info :: String
+  } deriving Show
 
 connect :: String -> PortNumber -> String -> String -> IO Handle
 connect host port user pass = do
   session <- connectTo host $ PortNumber port
+  hSetEncoding session utf8
   hSetBuffering session $ BlockBuffering $ Just 4096
   resp <- readString session
   let (code, nonce) = case elemIndex ':' resp of
@@ -32,28 +32,29 @@
     else error "Access denied."
   where md5 = show . MD5.md5 . fromString
 
-execute :: Handle -> String -> IO Result
-execute session cmd = do
+execute :: String -> Handle -> IO Result
+execute cmd session = do
   writeString session cmd
   content <- readString session
   info <- readString session
-  ok session <$$> \b -> if b
-    then Result{content, info}
+  result <- ok session <$$> \b -> if b
+    then Result { content, info }
     else error info
+  evaluate result
 
-query :: Handle -> String -> IO Query
-query session q = do
-  ident <- exec session 0 [q]
-  return $ Query session ident
+query :: String -> Handle -> IO Query
+query q session = do
+  ident <- exec 0 [q] session
+  return Query { session, ident }
 
-create, add, replace, store :: Handle -> String -> String -> IO String
-create = sendInput 8
-add = sendInput 9
+create, add, replace, store :: String -> String -> Handle -> IO String
+create  = sendInput 8
+add     = sendInput 9
 replace = sendInput 12
-store = sendInput 13
+store   = sendInput 13
 
-sendInput :: Int -> Handle -> String -> String -> IO String
-sendInput code session arg input = exec session code [arg, input]
+sendInput :: Int -> String -> String -> Handle -> IO String
+sendInput code arg input = exec code [arg, input]
 
 close :: Handle -> IO ()
 close session = do
diff --git a/src/BaseXClient/Utils.hs b/src/BaseXClient/Utils.hs
--- a/src/BaseXClient/Utils.hs
+++ b/src/BaseXClient/Utils.hs
@@ -1,17 +1,19 @@
 module BaseXClient.Utils where
 
 import Control.Applicative
+import Control.Exception
 import Data.Char
 import System.IO
 
-exec :: Handle -> Int -> [String] -> IO String
-exec h code strs = do
+exec :: Int -> [String] -> Handle -> IO String
+exec code args h = do
   writeCode h code
-  writeStrings h strs
+  writeStrings h args
   info <- readString h
-  ok h <$$> \b -> if b
+  result <- ok h <$$> \b -> if b
     then info
     else error info
+  evaluate result
 
 readString :: Handle -> IO String
 readString h = do
diff --git a/src/CreateExample.hs b/src/CreateExample.hs
--- a/src/CreateExample.hs
+++ b/src/CreateExample.hs
@@ -6,6 +6,6 @@
 
 main :: IO ()
 main = withSession "localhost" 1984 "admin" "admin" $ \session -> do
-  create session "database" "<x>Hello World!</x>" >>= print
-  execute session "xquery /" >>= print
-  execute session "drop db database" >>= print
+  create "database" "<x>Hello World!</x>" session >>= print
+  execute "xquery /" session >>= print
+  execute "drop db database" session >>= print
diff --git a/src/Example.hs b/src/Example.hs
--- a/src/Example.hs
+++ b/src/Example.hs
@@ -1,14 +1,15 @@
 module Example where
 
 import BaseXClient
+import Control.Monad
 import System.CPUTime
 import Text.Printf
 
 main :: IO ()
 main = do
   start <- getCPUTime
-  withSession "localhost" 1984 "admin" "admin" $ \session ->
-    execute session "xquery 1 to 10" >>= print
+  withSession "localhost" 1984 "admin" "admin"
+    $ execute "xquery 1 to 10" >=> print
   end <- getCPUTime
   let diff = fromIntegral (end - start) / (10 ^ 12)
   printf "Computation time: %0.3f sec\n" (diff :: Double)
diff --git a/src/QueryBindExample.hs b/src/QueryBindExample.hs
--- a/src/QueryBindExample.hs
+++ b/src/QueryBindExample.hs
@@ -8,5 +8,5 @@
 main :: IO ()
 main = withSession "localhost" 1984 "admin" "admin" $ \session ->
   withQuery session query $ \q -> do
-    bind q "name" "number" ""
+    bind "name" "number" "" q
     executeQuery q >>= print
diff --git a/src/QueryExample.hs b/src/QueryExample.hs
--- a/src/QueryExample.hs
+++ b/src/QueryExample.hs
@@ -1,8 +1,9 @@
 module QueryExample where
 
 import BaseXClient
+import Control.Monad
 
 main :: IO ()
 main = withSession "localhost" 1984 "admin" "admin" $ \session ->
-  withQuery session "for $i in 1 to 10 return <xml>Text { $i }</xml>" $ \q ->
-    results q >>= print
+  withQuery session "for $i in 1 to 10 return <xml>Text { $i }</xml>"
+    $ results >=> print
