diff --git a/ethereum-client-haskell.cabal b/ethereum-client-haskell.cabal
--- a/ethereum-client-haskell.cabal
+++ b/ethereum-client-haskell.cabal
@@ -1,5 +1,5 @@
 name: ethereum-client-haskell
-version: 0.0.3
+version: 0.0.4
 cabal-version: >=1.10
 build-type: Simple
 author: Jamshid
@@ -19,7 +19,7 @@
   type:     git
   location: https://github.com/jamshidh/ethereum-client-haskell
   branch:   master
-  tag:      v0.0.3
+  tag:      v0.0.4
 
 executable ethereumH
     default-language: Haskell98
@@ -116,6 +116,16 @@
                  , array
                  , directory
     main-is: Main.hs
+    other-modules:
+                   Block
+                   Code
+                   Decompile1
+                   Decompile2
+                   DumpLevelDB
+                   Init
+                   Raw
+                   RLP
+                   State
     C-sources: fastNonceFinder/nonceFinder.c
     buildable: True
     hs-source-dirs: queryEth_src, src
diff --git a/queryEth_src/Block.hs b/queryEth_src/Block.hs
new file mode 100644
--- /dev/null
+++ b/queryEth_src/Block.hs
@@ -0,0 +1,39 @@
+
+module Block 
+    (
+     doit
+    ) where
+
+--import Control.Monad.IO.Class
+import Control.Monad.Trans.Resource
+--import qualified Data.ByteString as B
+--import qualified Data.ByteString.Base16 as B16
+--import qualified Data.ByteString.Char8 as BC
+import Data.Default
+import qualified Database.LevelDB as DB
+--import System.Directory
+--import System.Environment
+import System.FilePath
+import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (</>))
+
+import Blockchain.Data.RLP
+
+import Blockchain.Data.Block
+
+import DumpLevelDB
+
+import Blockchain.Format
+
+--import Debug.Trace
+
+formatBlock::Block->String
+formatBlock = format
+
+doit::String->String->IO ()
+doit dbtype h = showKeyVal (formatBlock . rlpDecode . rlpDeserialize) dbtype "blocks" (if h == "-" then Nothing else Just h)
+
+
+
+
+
+
diff --git a/queryEth_src/Code.hs b/queryEth_src/Code.hs
new file mode 100644
--- /dev/null
+++ b/queryEth_src/Code.hs
@@ -0,0 +1,33 @@
+
+module Code
+    (
+     doit
+    ) where
+
+import Control.Monad.Trans.Resource
+import Data.Default
+import qualified Database.LevelDB as DB
+import System.FilePath
+import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (</>))
+
+import Blockchain.Data.RLP
+
+import Blockchain.VM.Code
+
+import DumpLevelDB
+
+import Blockchain.Format
+
+--import Debug.Trace
+
+formatCode::Code->String
+formatCode = show . pretty
+
+doit::String->String->IO ()
+doit dbtype h = showKeyVal (formatCode . Code) dbtype "state" (if h == "-" then Nothing else Just h)
+
+
+
+
+
+
diff --git a/queryEth_src/Decompile1.hs b/queryEth_src/Decompile1.hs
new file mode 100644
--- /dev/null
+++ b/queryEth_src/Decompile1.hs
@@ -0,0 +1,88 @@
+
+module Decompile1
+    (
+     decompile
+    ) where
+
+import Control.Monad.Trans.Resource
+import Data.Default
+import qualified Database.LevelDB as DB
+import Data.List
+import System.FilePath
+import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (</>))
+
+import Blockchain.Data.RLP
+
+import Blockchain.Data.Block
+import Blockchain.Data.SignedTransaction
+import Blockchain.Data.Transaction
+import Blockchain.Data.TransactionReceipt
+import Blockchain.Util
+import Blockchain.VM.Code
+import Blockchain.VM.Opcodes
+--
+import DumpLevelDB
+
+import Blockchain.Format
+
+--import Debug.Trace
+
+formatBlock::Block->String
+formatBlock = format
+
+data StackElement = StackNumber Int | ItemDescription String deriving (Show)
+
+stackElementSum::StackElement->StackElement->String
+stackElementSum (StackNumber x) (StackNumber y) = show $ x+y
+
+formatSE::StackElement->String
+formatSE (StackNumber x) = show x
+formatSE (ItemDescription s) = s
+
+decompile::Code->String
+decompile = decompile' [] 0
+
+decompile'::[StackElement]->Int->Code->String
+decompile' stack p c = 
+    case (op, stack) of
+      (STOP, _) -> "STOP"
+      (RETURN, [memP, memSize]) -> "RETURN Mem[" ++ formatSE memP ++ ":" ++ show (memP `stackElementSum` memSize) ++ "]"
+      (CALLER, _) -> decompile' (ItemDescription "$CALLER":stack) (p+size) c
+      (GAS, _) -> decompile' (ItemDescription "$GAS":stack) (p+size) c
+      (POP, _:rest) -> decompile' rest (p+size) c
+      (SWAP1, first:second:rest) -> decompile' (second:first:rest) (p+size) c
+      (DUP1, first:rest) -> decompile' (first:first:rest) (p+size) c
+      (DUP2, first:second:rest) -> decompile' (second:first:second:rest) (p+size) c
+      (DUP3, v1:i1:v2:rest) -> decompile' (v2:i1:v1:rest) (p+size) c
+      (DUP4, v1:i1:i2:v2:rest) -> decompile' (v2:i1:i2:v1:rest) (p+size) c
+      (DUP5, v1:i1:i2:i3:v2:rest) -> decompile' (v2:i1:i2:i3:v1:rest) (p+size) c
+      (DUP6, v1:i1:i2:i3:i4:v2:rest) -> decompile' (v2:i1:i2:i3:i4:v1:rest) (p+size) c
+      (EXP, v1:v2:rest) -> decompile' (ItemDescription (formatSE v1 ++ "^" ++ formatSE v2):rest) (p+size) c
+      (SUB, v1:v2:rest) -> decompile' (ItemDescription (formatSE v1 ++ "-" ++ formatSE v2):rest) (p+size) c
+      (AND, v1:v2:rest) -> decompile' (ItemDescription (formatSE v1 ++ " AND " ++ formatSE v2):rest) (p+size) c
+
+      (PUSH val, _) -> decompile' (StackNumber (fromInteger $ bytes2Integer val):stack) (p+size) c
+      (SSTORE, (key:val:rest)) -> "STORE[" ++ formatSE key ++ "] = " ++ formatSE val ++ "\n" ++ decompile' rest (p+size) c
+      (MLOAD, (memP:rest)) -> decompile' (ItemDescription ("Mem[" ++ formatSE memP ++ "]"):rest) (p+size) c
+      (CALLDATALOAD, (dataP:rest)) -> decompile' (ItemDescription ("Data[" ++ formatSE dataP ++ "]"):rest) (p+size) c
+      (MSTORE, (memP:val:rest)) -> "Mem[" ++ formatSE memP ++ "] = " ++ formatSE val ++ "\n" ++ decompile' rest (p+size) c
+      (CODECOPY, memP:codeP:codeSize:rest) -> "CODECOPY from CODE[" ++ formatSE codeP ++ ":" ++ show (codeP `stackElementSum` codeSize) ++ "] to Mem[" ++ formatSE memP ++ ":" ++ show (memP `stackElementSum` codeSize) ++ "]\n" ++ decompile' rest (p+size) c
+      (CALL, gas:to:value:inOffset:inSize:outOffset:outSize:rest) -> "CALL[" ++ formatSE to ++ "] (gas=" ++ formatSE gas ++ ", value=" ++ formatSE value ++ ", inOffset = " ++ formatSE inOffset ++ ", inSize=" ++ formatSE inSize ++ ", outOffset=" ++ formatSE outOffset ++ ", outSize=" ++ formatSE outSize ++ ")\n" ++ decompile' (ItemDescription "<call result>":rest) (p+size) c
+      (CALL, stack) -> "CALL messup: " ++ show stack
+      (CALLCODE, gas:to:value:inOffset:inSize:outOffset:outSize:rest) -> "CALLCODE[" ++ formatSE to ++ "] (gas=" ++ formatSE gas ++ ", value=" ++ formatSE value ++ ", inOffset = " ++ formatSE inOffset ++ ", inSize=" ++ formatSE inSize ++ ", outOffset=" ++ formatSE outOffset ++ ", outSize=" ++ formatSE outSize ++ ")\n" ++ decompile' rest (p+size) c
+      (CALLCODE, stack) -> "CALLCODE messup: " ++ show stack
+      (JUMP, StackNumber location:rest) -> "JUMP to " ++ show location ++ "\n" ++ decompile' rest location c
+      (JUMP, ItemDescription location:rest) -> "JUMP to " ++ show location ++ "\n" ++ decompile' rest (p+size) c
+      (JUMP, _) -> "JUMP messup: " ++ show stack
+      _ -> show op ++ "\n" ++ decompile' stack (p+size) c
+    where
+      (op, size) = getOperationAt c p
+
+
+showInit::Transaction->String
+showInit ContractCreationTX {tInit=tInit'} = show (pretty tInit') ++ "\n----\n" ++ decompile tInit'
+showInit MessageTX {} = ""
+
+
+
+
diff --git a/queryEth_src/Decompile2.hs b/queryEth_src/Decompile2.hs
new file mode 100644
--- /dev/null
+++ b/queryEth_src/Decompile2.hs
@@ -0,0 +1,168 @@
+
+module Decompile2
+    (
+     decompile,
+     formatSequence
+    ) where
+
+import Data.Functor
+import Data.List
+import qualified Data.Map as M
+import Data.Maybe
+
+import Blockchain.VM.Code
+import Blockchain.VM.Opcodes
+
+import Blockchain.Util
+
+import Debug.Trace
+
+data Sequence = Sequence Integer [Command] deriving (Show, Eq)
+
+data Expression = Number Integer | Variable String | Unary String Expression | Binary String Expression Expression | Function String [Expression] deriving (Show, Eq)
+
+data Command = OpCommand Operation | JumpDest Integer | Command Expression | Put Expression | StackFunction String Int Int | Subroutine Integer deriving (Show, Eq)
+
+getSequence::Integer->Code->Sequence
+getSequence p code = Sequence p $ code2Commands p code
+
+op2Command::Operation->Command
+op2Command CALLER = Put $ Variable "caller"
+op2Command GAS = Put $ Variable "gas"
+op2Command (PUSH x) = Put $ Number $ bytes2Integer x
+op2Command JUMP = StackFunction "jump" 1 0
+op2Command CODECOPY = StackFunction "codecopy" 3 0
+op2Command CALL = StackFunction "call" 7 1
+op2Command SSTORE = StackFunction "sstore" 2 0
+op2Command MSTORE = StackFunction "mstore" 2 0
+op2Command RETURN = StackFunction "return" 2 0
+op2Command EXP = StackFunction "exp" 2 1
+op2Command SUB = StackFunction "sub" 2 1
+op2Command AND = StackFunction "and" 2 1
+op2Command MLOAD = StackFunction "mload" 1 1
+op2Command op = OpCommand op
+
+code2Commands::Integer->Code->[Command]
+code2Commands i o | op == JUMPDEST = JumpDest i:code2Commands (i+fromIntegral opSize) o
+                  | op == STOP = [op2Command STOP]
+                  | op == RETURN = [op2Command RETURN]
+                  | otherwise = op2Command op:code2Commands (i+fromIntegral opSize) o
+    where 
+      (op, opSize) = getOperationAt o (fromIntegral i)
+
+hasNoSideEffects::Expression->Bool
+hasNoSideEffects (Function "call" _) = False
+hasNoSideEffects x = error $ "Missing case in hasNoSideEffects: " ++ show x
+
+simplifyCommands::Code->[Command]->[Command]
+simplifyCommands code (c@(Command (Function "jump" [Number loc])):rest) | not (codeReturns code loc) = [c]
+simplifyCommands code (Put (Number loc1):Command (Function "jump" [Number loc]):JumpDest loc2:rest) | loc1 == loc2 && codeReturns code loc = Subroutine loc:simplifyCommands code rest
+simplifyCommands code (Put x:StackFunction name 1 0:rest) = Command (Function name [x]):simplifyCommands code rest
+simplifyCommands code (Put x:StackFunction name 1 1:rest) = Put (Function name [x]):simplifyCommands code rest
+simplifyCommands code (Put x:Put y:StackFunction name 2 1:rest) = Put (Function name [y, x]):simplifyCommands code rest
+simplifyCommands code (Put x:Put y:StackFunction name 2 0:rest) = Command (Function name [y, x]):simplifyCommands code rest
+simplifyCommands code (Put v1:Put v2:Put v3:StackFunction name 3 1:rest) = Put (Function name [v3, v2, v1]):simplifyCommands code rest
+simplifyCommands code (Put v1:Put v2:Put v3:StackFunction name 3 0:rest) = Command (Function name [v3, v2, v1]):simplifyCommands code rest
+simplifyCommands code (Put v1:Put v2:Put v3:Put v4:Put v5:Put v6:Put v7:StackFunction name 7 1:rest) = Put (Function name [v7, v6, v5, v4, v3, v2, v1]):simplifyCommands code rest
+simplifyCommands code (Put x:OpCommand DUP1:rest) = Put x:Put x:simplifyCommands code rest
+simplifyCommands code (Put x:Put y:OpCommand DUP2:rest) = Put y:Put x:Put y:simplifyCommands code rest
+simplifyCommands code (Put x:Put y:OpCommand SWAP1:rest) = Put y:Put x:simplifyCommands code rest
+simplifyCommands code (Put y:OpCommand POP:rest) | hasNoSideEffects y = simplifyCommands code rest
+simplifyCommands code (Put (Number x):cmd@(Command c):rest) | not (isJump cmd) = Command c:Put (Number x):simplifyCommands code rest
+simplifyCommands _ [] = []
+simplifyCommands code (x:rest) = x:simplifyCommands code rest
+
+simplify::Code->Sequence->Sequence
+simplify code (Sequence location commands) = Sequence location $ simplifyCommands code commands
+
+formatExpression::Expression->String
+formatExpression (Variable name) = "$" ++ name
+formatExpression (Number x) = show x
+formatExpression (Function "sload" [p]) = "store[" ++ formatExpression p ++ "]"
+formatExpression (Function "mload" [p]) = "mem[" ++ formatExpression p ++ "]"
+formatExpression (Function "sstore" [key, val]) = "store[" ++ formatExpression key ++ "] = " ++ formatExpression val 
+formatExpression (Function "mstore" [key, val]) = "mem[" ++ formatExpression key ++ "] = " ++ formatExpression val 
+formatExpression (Function "exp" [v1, v2]) = formatExpression v1 ++ "^" ++ formatExpression v2
+formatExpression (Function "sub" [v1, v2]) = formatExpression v1 ++ " - " ++ formatExpression v2
+formatExpression (Function "and" [v1, v2]) = formatExpression v1 ++ " AND " ++ formatExpression v2
+formatExpression (Function name params) = name ++ "(" ++ intercalate ", " (map formatExpression params) ++ ")"
+formatExpression x = show x
+
+formatCommand::Command->String
+formatCommand (Put x) = "put " ++ formatExpression x
+formatCommand (Command x) = formatExpression x
+formatCommand x = show x
+
+formatSequence::Sequence->String
+formatSequence (Sequence location commands) = "Sequence at " ++ show location ++ "\n" ++ unlines (map formatCommand commands)
+
+countMap = M.fromList $ (\(OPData _ op stackOut stackIn _) -> (op, (stackOut, stackIn))) <$> opDatas
+
+getOpCount::Operation->(Int, Int)
+getOpCount (PUSH _) = (0, 1)
+getOpCount x = fromMaybe (error $ "Missing value in countMap: " ++ show x) $ M.lookup x countMap
+-- getOpCount x = error $ "Missing case in getOpCount: " ++ show x
+
+codeReturns'::Code->Integer->Integer->Bool
+codeReturns' code p count | op == JUMP = trace ("            the count is: " ++ show count) $ count == 0
+                          | op == STOP = False
+                          | otherwise = let (use, ret) = getOpCount op in codeReturns' code (p + fromIntegral size) (count + toInteger use - toInteger ret)
+    where 
+      (op, size) = getOperationAt code $ fromIntegral p
+
+codeReturns::Code->Integer->Bool
+codeReturns code p = trace ("             pppppppppppppppppppppppp: " ++ show x) $ x where x = codeReturns' code p 0
+
+converge::Eq a=>(a->a)->a->a
+converge f x | f x == x = x
+             | otherwise = converge f (f x)
+
+decompileSequence::Code->Integer->Sequence
+decompileSequence c p = converge (simplify c) $ getSequence p c
+--decompileSequence c p = simplify c $ simplify c $ simplify c $ simplify c $ simplify c $ getSequence p c -- converge (simplify c) $ getSequence p c
+
+getJumpLocations::Sequence->[Integer]
+getJumpLocations (Sequence _ commands) = getJumpLocations' commands
+    where
+      getJumpLocations'::[Command]->[Integer]
+      getJumpLocations' [] = []
+      getJumpLocations' (Command (Function "jump" [Number loc]):rest) = loc:getJumpLocations' rest
+      getJumpLocations' (Subroutine loc:rest) = loc:getJumpLocations' rest
+      getJumpLocations' (_:rest) = getJumpLocations' rest
+
+loc::Sequence->Integer
+loc (Sequence l _) = l
+
+commands::Sequence->[Command]
+commands (Sequence _ c) = c
+
+getMissingLocations::[Sequence]->[Integer]
+getMissingLocations seqs = (seqs >>= getJumpLocations) \\ map loc seqs
+
+addMissingSequencesPartial::Code->[Sequence]->[Sequence]
+addMissingSequencesPartial c seqs = seqs ++ map (decompileSequence c) (getMissingLocations seqs)
+
+isJump::Command->Bool
+isJump (Command (Function "jump" _)) = True
+isJump _ = False
+
+isJumpDest::Command->Bool
+isJumpDest (JumpDest _) = True
+isJumpDest _ = False
+
+
+
+simplifySeqs::Code->[Sequence]->[Sequence]
+simplifySeqs code [seq1@(Sequence l1 c1), seq2@(Sequence l2 (jd:rest2))] 
+    | length (getJumpLocations seq1) == 1 && length (getJumpLocations seq2) == 0 
+      && isJumpDest jd && isJump (last c1)
+          = [converge (simplify code) $ Sequence (loc seq1) (init c1 ++ rest2)]
+simplifySeqs _ seqs = seqs
+
+decompile::Code->[Sequence]
+decompile c = theSeqs -- simplifySeqs c theSeqs
+    where
+      theSeqs = converge addNeededSeqs [firstSeq]
+      firstSeq = decompileSequence c 0
+      addNeededSeqs = addMissingSequencesPartial c
+
diff --git a/queryEth_src/DumpLevelDB.hs b/queryEth_src/DumpLevelDB.hs
new file mode 100644
--- /dev/null
+++ b/queryEth_src/DumpLevelDB.hs
@@ -0,0 +1,72 @@
+
+module DumpLevelDB 
+    (
+     showKeyVal,
+     typeToDB
+    ) where
+
+import Control.Monad.IO.Class
+import Control.Monad.Trans.Resource
+import qualified Data.ByteString as B
+import qualified Data.ByteString.Base16 as B16
+import qualified Data.ByteString.Char8 as BC
+import Data.Default
+import qualified Database.LevelDB as DB
+import System.Directory
+import System.Environment
+import System.FilePath
+import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (</>))
+
+import Blockchain.Data.RLP
+
+--import Debug.Trace
+
+instance Pretty B.ByteString where
+  pretty = blue . text . BC.unpack . B16.encode
+
+showAllKeyVal::DB.DB->(B.ByteString->String)->ResourceT IO ()
+showAllKeyVal db f = do
+  i <- DB.iterOpen db def
+  DB.iterFirst i
+  valid <- DB.iterValid i
+  if valid
+    then showAllKeyVal' db i
+    else liftIO $ putStrLn "no keys"
+  where
+    showAllKeyVal'::DB.DB->DB.Iterator->ResourceT IO ()
+    showAllKeyVal' db' i = do
+      Just key <- DB.iterKey i
+      Just val <- DB.iterValue i
+      if B.null val
+        then liftIO $ putStrLn $ "----------\n" ++ show (pretty key) ++ ": <BLANK>"
+        else liftIO $ putStrLn $ "----------\n" ++ show (pretty key) ++ ": " ++ f val
+      DB.iterNext i
+      v <- DB.iterValid i
+      if v
+        then showAllKeyVal' db' i
+        else return ()
+
+showKeyVal::(B.ByteString->String)->String->String->Maybe String->IO ()
+showKeyVal f dbType dbName maybeKey = do
+  let options = DB.defaultOptions {
+        DB.createIfMissing=True, DB.cacheSize=1024}
+  dbDir <- typeToDB dbType
+  runResourceT $ do
+    db <- DB.open (dbDir </> dbName) def
+    case maybeKey of
+      Nothing -> showAllKeyVal db f
+      Just key -> do
+                   maybeVal <- DB.get db def $ fst $ B16.decode $ BC.pack key
+                   case maybeVal of
+                     Nothing -> error $ "Missing value in database: " ++ show key
+                     Just val -> liftIO $ putStrLn $ f val
+
+
+typeToDB::String->IO String
+typeToDB "h" = do
+  homeDir <- getHomeDirectory
+  return $ homeDir </> ".ethereumH"
+typeToDB "c" = do
+  homeDir <- getHomeDirectory
+  return $ homeDir </> "Library" </> "Application Support" </> "Ethereum"
+
diff --git a/queryEth_src/Init.hs b/queryEth_src/Init.hs
new file mode 100644
--- /dev/null
+++ b/queryEth_src/Init.hs
@@ -0,0 +1,92 @@
+
+module Init
+    (
+     doit
+    ) where
+
+import Control.Monad.Trans.Resource
+import Data.Default
+import qualified Database.LevelDB as DB
+import Data.List
+import System.FilePath
+import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (</>))
+
+import Blockchain.Data.RLP
+
+import Blockchain.Data.Block
+import Blockchain.Data.SignedTransaction
+import Blockchain.Data.Transaction
+import Blockchain.Data.TransactionReceipt
+import Blockchain.Util
+import Blockchain.VM.Code
+import Blockchain.VM.Opcodes
+
+import Decompile1
+import DumpLevelDB
+
+import Blockchain.Format
+
+--import Debug.Trace
+
+formatBlock::Block->String
+formatBlock = format
+
+data StackElement = StackNumber Int | ItemDescription String deriving (Show)
+
+stackElementSum::StackElement->StackElement->String
+stackElementSum (StackNumber x) (StackNumber y) = show $ x+y
+
+formatSE::StackElement->String
+formatSE (StackNumber x) = show x
+formatSE (ItemDescription s) = s
+
+decompile'::[StackElement]->Int->Code->String
+decompile' stack p c = 
+    case (op, stack) of
+      (STOP, _) -> "STOP"
+      (RETURN, [memP, memSize]) -> "RETURN Mem[" ++ formatSE memP ++ ":" ++ show (memP `stackElementSum` memSize) ++ "]"
+      (CALLER, _) -> decompile' (ItemDescription "$CALLER":stack) (p+size) c
+      (GAS, _) -> decompile' (ItemDescription "$GAS":stack) (p+size) c
+      (POP, _:rest) -> decompile' rest (p+size) c
+      (SWAP1, first:second:rest) -> decompile' (second:first:rest) (p+size) c
+      (DUP1, first:rest) -> decompile' (first:first:rest) (p+size) c
+      (DUP2, first:second:rest) -> decompile' (second:first:second:rest) (p+size) c
+      (DUP3, v1:i1:v2:rest) -> decompile' (v2:i1:v1:rest) (p+size) c
+      (DUP4, v1:i1:i2:v2:rest) -> decompile' (v2:i1:i2:v1:rest) (p+size) c
+      (DUP5, v1:i1:i2:i3:v2:rest) -> decompile' (v2:i1:i2:i3:v1:rest) (p+size) c
+      (DUP6, v1:i1:i2:i3:i4:v2:rest) -> decompile' (v2:i1:i2:i3:i4:v1:rest) (p+size) c
+      (EXP, v1:v2:rest) -> decompile' (ItemDescription (formatSE v1 ++ "^" ++ formatSE v2):rest) (p+size) c
+      (SUB, v1:v2:rest) -> decompile' (ItemDescription (formatSE v1 ++ "-" ++ formatSE v2):rest) (p+size) c
+      (AND, v1:v2:rest) -> decompile' (ItemDescription (formatSE v1 ++ " AND " ++ formatSE v2):rest) (p+size) c
+
+      (PUSH val, _) -> decompile' (StackNumber (fromInteger $ bytes2Integer val):stack) (p+size) c
+      (SSTORE, (key:val:rest)) -> "STORE[" ++ formatSE key ++ "] = " ++ formatSE val ++ "\n" ++ decompile' rest (p+size) c
+      (MLOAD, (memP:rest)) -> decompile' (ItemDescription ("Mem[" ++ formatSE memP ++ "]"):rest) (p+size) c
+      (CALLDATALOAD, (dataP:rest)) -> decompile' (ItemDescription ("Data[" ++ formatSE dataP ++ "]"):rest) (p+size) c
+      (MSTORE, (memP:val:rest)) -> "Mem[" ++ formatSE memP ++ "] = " ++ formatSE val ++ "\n" ++ decompile' rest (p+size) c
+      (CODECOPY, memP:codeP:codeSize:rest) -> "CODECOPY from CODE[" ++ formatSE codeP ++ ":" ++ show (codeP `stackElementSum` codeSize) ++ "] to Mem[" ++ formatSE memP ++ ":" ++ show (memP `stackElementSum` codeSize) ++ "]\n" ++ decompile' rest (p+size) c
+      (CALL, gas:to:value:inOffset:inSize:outOffset:outSize:rest) -> "CALL[" ++ formatSE to ++ "] (gas=" ++ formatSE gas ++ ", value=" ++ formatSE value ++ ", inOffset = " ++ formatSE inOffset ++ ", inSize=" ++ formatSE inSize ++ ", outOffset=" ++ formatSE outOffset ++ ", outSize=" ++ formatSE outSize ++ ")\n" ++ decompile' (ItemDescription "<call result>":rest) (p+size) c
+      (CALL, stack) -> "CALL messup: " ++ show stack
+      (CALLCODE, gas:to:value:inOffset:inSize:outOffset:outSize:rest) -> "CALLCODE[" ++ formatSE to ++ "] (gas=" ++ formatSE gas ++ ", value=" ++ formatSE value ++ ", inOffset = " ++ formatSE inOffset ++ ", inSize=" ++ formatSE inSize ++ ", outOffset=" ++ formatSE outOffset ++ ", outSize=" ++ formatSE outSize ++ ")\n" ++ decompile' rest (p+size) c
+      (CALLCODE, stack) -> "CALLCODE messup: " ++ show stack
+      (JUMP, StackNumber location:rest) -> "JUMP to " ++ show location ++ "\n" ++ decompile' rest location c
+      (JUMP, ItemDescription location:rest) -> "JUMP to " ++ show location ++ "\n" ++ decompile' rest (p+size) c
+      (JUMP, _) -> "JUMP messup: " ++ show stack
+      _ -> show op ++ "\n" ++ decompile' stack (p+size) c
+    where
+      (op, size) = getOperationAt c p
+
+
+showInit::Transaction->String
+showInit ContractCreationTX {tInit=tInit'} = show (pretty tInit') ++ "\n----\n" ++ intercalate "===========" (map show (decompile tInit')) -- (map formatSequence (decompile tInit'))
+showInit MessageTX {} = ""
+
+
+doit::String->String->IO ()
+doit dbtype h = showKeyVal (intercalate "\n" . map (showInit . unsignedTransaction) . receiptTransactions . rlpDecode . rlpDeserialize) dbtype "blocks" (if h == "-" then Nothing else Just h)
+
+
+
+
+
+
diff --git a/queryEth_src/RLP.hs b/queryEth_src/RLP.hs
new file mode 100644
--- /dev/null
+++ b/queryEth_src/RLP.hs
@@ -0,0 +1,38 @@
+
+module RLP
+    (
+     doit
+    ) where
+
+import Control.Monad.IO.Class
+import Control.Monad.Trans.Resource
+import qualified Data.ByteString as B
+import qualified Data.ByteString.Base16 as B16
+import qualified Data.ByteString.Char8 as BC
+import Data.Default
+import qualified Database.LevelDB as DB
+import System.Directory
+import System.Environment
+import System.FilePath
+import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (</>))
+
+import Blockchain.Data.RLP
+
+import DumpLevelDB
+
+--import Debug.Trace
+
+doit::String->String->IO ()
+doit dbtype h = do
+  let options = DB.defaultOptions {
+        DB.createIfMissing=True, DB.cacheSize=1024}
+  dbDir <- typeToDB dbtype
+  runResourceT $ do
+    db <- DB.open (dbDir </> "blocks") def
+    showAllKeyVal db (show . pretty . rlpDeserialize)
+
+
+
+
+
+
diff --git a/queryEth_src/Raw.hs b/queryEth_src/Raw.hs
new file mode 100644
--- /dev/null
+++ b/queryEth_src/Raw.hs
@@ -0,0 +1,38 @@
+
+module Raw
+    (
+     doit
+    ) where
+
+import Control.Monad.IO.Class
+import Control.Monad.Trans.Resource
+import qualified Data.ByteString as B
+import qualified Data.ByteString.Base16 as B16
+import qualified Data.ByteString.Char8 as BC
+import Data.Default
+import qualified Database.LevelDB as DB
+import System.Directory
+import System.Environment
+import System.FilePath
+import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (</>))
+
+import Data.RLP
+
+import DumpLevelDB
+
+--import Debug.Trace
+
+doit::String->String->IO ()
+doit dbtype h = do
+  let options = DB.defaultOptions {
+        DB.createIfMissing=True, DB.cacheSize=1024}
+  dbDir <- typeToDB dbtype
+  runResourceT $ do
+    db <- DB.open (dbDir </> "blocks") def
+    showAllKeyVal db (show . pretty)
+
+
+
+
+
+
diff --git a/queryEth_src/State.hs b/queryEth_src/State.hs
new file mode 100644
--- /dev/null
+++ b/queryEth_src/State.hs
@@ -0,0 +1,60 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module State 
+    (
+     doit
+    ) where
+
+import Control.Monad.IO.Class
+import Control.Monad.State
+import qualified Data.ByteString as B
+import qualified Data.ByteString.Base16 as B16
+import qualified Data.ByteString.Char8 as BC
+import Data.Functor
+import Data.List
+import qualified Database.LevelDB as DB
+import System.Environment
+import Text.PrettyPrint.ANSI.Leijen hiding ((<$>))
+
+import qualified Data.NibbleString as N
+import Blockchain.Data.RLP
+
+import Blockchain.Context
+import Blockchain.ExtDBs
+import Blockchain.Format
+
+formatKV::(N.NibbleString, RLPObject)->Doc
+formatKV (key, val) =
+    pretty key <> text ": " <> pretty (rlpDeserialize $ rlpDecode val)
+
+showVals::SHAPtr->ContextM ()
+showVals sr = do
+    setStateRoot sr
+    kvs <- getKeyVals ""
+    --liftIO $ putStrLn $ displayS (renderPretty 1.0 200 $ vsep $ formatKV <$> kvs) ""
+    liftIO $ putStrLn $ displayS (renderPretty 1.0 200 $ vsep $ formatKV <$> filter (filterUnnecessary . fst) kvs) ""
+
+doit::String->SHAPtr->IO()
+doit theType sr = do
+  DB.runResourceT $ do
+    cxt <- openDBs theType
+    _ <- liftIO $ runStateT (showVals sr) cxt
+    return ()
+
+filterUnnecessary::N.NibbleString->Bool
+filterUnnecessary "1a26338f0d905e295fccb71fa9ea849ffa12aaf4" = False
+filterUnnecessary "2ef47100e0787b915105fd5e3f4ff6752079d5cb" = False
+filterUnnecessary "51ba59315b3a95761d0863b05ccc7a7f54703d99" = False
+filterUnnecessary "6c386a4b26f73c802f34673f7248bb118f97424a" = False
+filterUnnecessary "b9c015918bdaba24b4ff057a92a3873d6eb201be" = False
+filterUnnecessary "cd2a3d9f938e13cd947ec05abc7fe734df8dd826" = False
+filterUnnecessary "e4157b34ea9615cfbde6b4fda419828124b70c78" = False
+filterUnnecessary "e6716f9544a56c530d868e4bfbacb172315bdead" = False
+filterUnnecessary _ = True
+
+
+
+
+
+
+                      
