diff --git a/cabal-sort.cabal b/cabal-sort.cabal
--- a/cabal-sort.cabal
+++ b/cabal-sort.cabal
@@ -1,5 +1,5 @@
 Name:             cabal-sort
-Version:          0.0.2.1
+Version:          0.0.3
 License:          BSD3
 License-File:     LICENSE
 Author:           Henning Thielemann <haskell@henning-thielemann.de>
@@ -62,7 +62,7 @@
 Source-Repository this
   type:     darcs
   location: http://code.haskell.org/~thielema/cabal-sort/
-  tag:      0.0.2.1
+  tag:      0.0.3
 
 
 Executable cabal-sort
@@ -85,7 +85,8 @@
     Cabal >=1.6 && <1.11,
     process >=1.0 && <1.1,
     containers >=0.2 && <0.5,
-    explicit-exception >=0.1.4 && <0.2,
+    explicit-exception >=0.1.6 && <0.2,
+    utility-ht >=0.0.5 && <0.1,
     transformers >=0.2 && <0.3,
     bytestring >=0.9.1 && <0.10,
     base >=2 && <5
diff --git a/src/CabalSort.hs b/src/CabalSort.hs
--- a/src/CabalSort.hs
+++ b/src/CabalSort.hs
@@ -3,7 +3,7 @@
 import qualified Distribution.PackageDescription as P
 import Distribution.PackageDescription
          (GenericPackageDescription, PackageDescription,
-          package, packageDescription, buildDepends, )
+          package, packageDescription, )
 import Distribution.PackageDescription.Parse (readPackageDescription, )
 import Distribution.Package
          (Dependency(Dependency), PackageName(PackageName), pkgName, )
diff --git a/src/GhcPkgDep.hs b/src/GhcPkgDep.hs
--- a/src/GhcPkgDep.hs
+++ b/src/GhcPkgDep.hs
@@ -1,10 +1,6 @@
 module Main where
 
-import qualified Distribution.Verbosity as Verbosity
-import qualified Distribution.ReadE as ReadE
-
 import qualified System.Process as Proc
-import qualified System.Exit as Exit
 import qualified System.IO as IO
 
 import System.Console.GetOpt
@@ -26,6 +22,9 @@
 
 import qualified Data.ByteString.Char8 as B
 
+import qualified Data.List.HT as ListHT
+import qualified Data.List as List
+import qualified Data.Char as Char
 import Control.Monad (when, guard, )
 import Data.Maybe (fromMaybe, )
 
@@ -58,7 +57,8 @@
       optHelp :: Bool,
       optVerbosity :: Verbosity.Verbosity,
       optUser, optGlobal :: Bool,
-      optShowVersions :: Bool
+      optShowVersions :: Bool,
+      optPkgCmd :: String
    }
 
 defltFlags :: Flags
@@ -68,7 +68,8 @@
       optVerbosity = Verbosity.silent,
       optUser = False,
       optGlobal = False,
-      optShowVersions = False
+      optShowVersions = False,
+      optPkgCmd = "ghc-pkg"
    }
 
 options :: [OptDescr (Flags -> Exc.Exceptional String Flags)]
@@ -93,6 +94,12 @@
    Option [] ["show-versions"]
       (NoArg (\flags -> return $ flags{optShowVersions = True}))
       "show package version numbers in the output" :
+   Option [] ["pkg-cmd"]
+      (ReqArg
+         (\str flags -> return flags{optPkgCmd = str})
+         "COMMAND")
+      ("command for querying the package database (default: " ++
+       optPkgCmd defltFlags ++ ")") :
    []
 
 
@@ -136,7 +143,7 @@
    Flags -> PkgName ->
    Exc.ExceptionalT String IO [PkgName]
 getDirectDependencies flags name = do
-   let cmd = "ghc-pkg"
+   let cmd = optPkgCmd flags
        args =
           (if optUser   flags then ("--user"   :) else id) $
           (if optGlobal flags then ("--global" :) else id) $
@@ -149,19 +156,40 @@
    errTxt <- Trans.lift $ B.hGetContents err
    when (optVerbosity flags >= Verbosity.normal) $
       Trans.lift $ putStr $ B.unpack errTxt
-   exit <- Trans.lift $ Proc.waitForProcess pid
-   case exit of
-      Exit.ExitSuccess -> return ()
-      Exit.ExitFailure n ->
-         Exc.throwT $
-            "ghc-pkg exited with code " ++ show n ++ "\n" ++ B.unpack errTxt
+   Exc.mapExceptionT (\n ->
+      "ghc-pkg exited with code " ++ show n ++ "\n" ++ B.unpack errTxt) $
+         Exc.fromExitCodeT $
+         Proc.waitForProcess pid
    Trans.lift (mapM_ IO.hClose [inp,out,err])
    case words (B.unpack txt) of
       "depends:":names ->
-         return (filter ("depends:"/=) names)
+         {-
+         If multiple packages are installed,
+         then the dependencies of each are preceded by a 'depends:' prefix.
+
+         ghc-pkg lists 'builtin_rts' as dependency of 'base',
+         but does not accept this identifier as package name,
+         since it contains an underscore.
+         -}
+         return $
+            map stripHashId $
+            filter (not . flip elem ["depends:", "builtin_rts"]) names
       _ -> Exc.throwT $
               "unexpected output of ghc-pkg - " ++
               "it should start with 'depends:'" ++
               if optVerbosity flags >= Verbosity.verbose
                 then "\n" ++ B.unpack txt
                 else ""
+
+stripHashId :: PkgName -> PkgName
+stripHashId name =
+   (\parts ->
+      let lastPart = last parts
+      in  if (not $ null $ drop 15 lastPart) &&
+             all Char.isHexDigit lastPart
+            then List.intercalate "-" $ init parts
+            else name)
+   .
+   ListHT.chop ('-'==)
+   $
+   name
