diff --git a/JVM/Assembler.hs b/JVM/Assembler.hs
--- a/JVM/Assembler.hs
+++ b/JVM/Assembler.hs
@@ -27,6 +27,7 @@
 import Data.BinaryState
 import JVM.ClassFile
 
+
 -- | Immediate constant. Corresponding value will be added to base opcode.
 data IMM =
     I0     -- ^ 0
@@ -245,8 +246,8 @@
   | GOTO Word16            -- ^ 167
   | JSR Word16             -- ^ 168
   | RET                    -- ^ 169
-  | TABLESWITCH Word32 Word32 Word32 [Word32]     -- ^ 170
-  | LOOKUPSWITCH Word32 Word32 [(Word32, Word32)] -- ^ 171
+  | TABLESWITCH Word8 Word32 Word32 Word32 [Word32]     -- ^ 170
+  | LOOKUPSWITCH Word8 Word32 Word32 [(Word32, Word32)] -- ^ 171
   | IRETURN                -- ^ 172
   | LRETURN                -- ^ 173
   | FRETURN                -- ^ 174
@@ -484,19 +485,19 @@
   put (GOTO x)        = put1 167 x
   put (JSR x)         = put1 168 x
   put  RET            = putByte 169
-  put (TABLESWITCH def low high offs) = do
+  put (TABLESWITCH _ def low high offs) = do
                                    putByte 170
                                    offset <- getOffset
-                                   let pads = 4 - (offset `mod` 4)
-                                   replicateM (fromIntegral pads) (putByte 0)
+                                   let pads = padding offset
+                                   replicateM pads (putByte 0)
                                    put low
                                    put high
                                    forM_ offs put
-  put (LOOKUPSWITCH def n pairs) = do
+  put (LOOKUPSWITCH _ def n pairs) = do
                                    putByte 171
                                    offset <- getOffset
-                                   let pads = 4 - (offset `mod` 4)
-                                   replicateM (fromIntegral pads) (putByte 0)
+                                   let pads = padding offset
+                                   replicateM pads (putByte 0)
                                    put def
                                    put n
                                    forM_ pairs put
@@ -653,21 +654,21 @@
       169 -> return RET
       170 -> do
              offset <- bytesRead
-             let pads = 4 - (offset `mod` 4)
-             skip (fromIntegral pads)
+             let pads = padding offset
+             skip pads
              def <- get
              low <- get
              high <- get
              offs <- replicateM (fromIntegral $ high - low + 1) get
-             return $ TABLESWITCH def low high offs
+             return $ TABLESWITCH (fromIntegral pads) def low high offs
       171 -> do
              offset <- bytesRead
-             let pads = 4 - (offset `mod` 4)
-             skip (fromIntegral pads)
+             let pads = padding offset
+             skip pads
              def <- get
              n <- get
              pairs <- replicateM (fromIntegral n) get
-             return $ LOOKUPSWITCH def n pairs
+             return $ LOOKUPSWITCH (fromIntegral pads) def n pairs
       172 -> return IRETURN
       173 -> return LRETURN
       174 -> return FRETURN
@@ -725,3 +726,6 @@
 encodeMethod :: Code -> B.ByteString
 encodeMethod code = encodeS (0 :: Integer) code
 
+-- | Calculate padding for current bytecode offset (cf. TABLESWITCH and LOOKUPSWITCH)
+padding :: (Integral a, Integral b) => a -> b
+padding offset = fromIntegral $ (4 - offset) `mod` 4
diff --git a/JVM/Builder/Monad.hs b/JVM/Builder/Monad.hs
--- a/JVM/Builder/Monad.hs
+++ b/JVM/Builder/Monad.hs
@@ -18,7 +18,8 @@
    setStackSize, setMaxLocals,
    withClassPath,
    getClassField, getClassMethod,
-   generate, generateIO
+   generate, generateIO,
+   generateCodeLength
   ) where
 
 import Prelude hiding (catch)
@@ -286,19 +287,24 @@
     Just m -> return (methodNameType m)
     Nothing  -> throwG (MethodNotFound clsName mName)
 
+-- | Access the generated bytecode length
+encodedCodeLength :: GState -> Word32
+encodedCodeLength st = fromIntegral . B.length . encodeInstructions $ generated st
+
+generateCodeLength :: Generate (Caught SomeException NoExceptions) a -> Word32
+generateCodeLength = encodedCodeLength . execGenerate []
+
 -- | Convert Generator state to method Code.
 genCode :: GState -> Code
 genCode st = Code {
     codeStackSize = stackSize st,
     codeMaxLocals = locals st,
-    codeLength = len,
+    codeLength = encodedCodeLength st,
     codeInstructions = generated st,
     codeExceptionsN = 0,
     codeExceptions = [],
     codeAttrsN = 0,
     codeAttributes = AP [] }
-  where
-    len = fromIntegral $ B.length $ encodeInstructions (generated st)
 
 -- | Start class generation.
 initClass :: (Generator e g) => B.ByteString -> g e Word16
diff --git a/JVM/Converter.hs b/JVM/Converter.hs
--- a/JVM/Converter.hs
+++ b/JVM/Converter.hs
@@ -67,7 +67,7 @@
     thisClass = force "this" $ poolClassIndex poolInfo thisClass,
     superClass = force "super" $ poolClassIndex poolInfo superClass,
     interfacesCount = fromIntegral (length interfaces),
-    interfaces = map (force "ifaces" . poolIndex poolInfo) interfaces,
+    interfaces = map (force "ifaces" . poolClassIndex poolInfo) interfaces,
     classFieldsCount = fromIntegral (length classFields),
     classFields = map (fieldDirect2File poolInfo) classFields,
     classMethodsCount = fromIntegral (length classMethods),
diff --git a/JVM/Exceptions.hs b/JVM/Exceptions.hs
--- a/JVM/Exceptions.hs
+++ b/JVM/Exceptions.hs
@@ -3,6 +3,7 @@
 
 import Control.Monad.Exception
 import qualified Data.ByteString.Lazy as B
+import Data.Typeable (Typeable)
 
 import JVM.ClassFile
 
diff --git a/hs-java.cabal b/hs-java.cabal
--- a/hs-java.cabal
+++ b/hs-java.cabal
@@ -1,5 +1,5 @@
 Name:           hs-java
-Version:        0.3.3
+Version:        0.3.4
 Cabal-Version:  >= 1.6
 License:        BSD3
 License-File:   LICENSE
