diff --git a/Data/ASN1/Raw.hs b/Data/ASN1/Raw.hs
--- a/Data/ASN1/Raw.hs
+++ b/Data/ASN1/Raw.hs
@@ -23,6 +23,7 @@
 	, iterateByteString
 	, enumReadBytes
 	, enumWriteBytes
+	, toBytes
 	-- * serialize asn1 headers
 	, getHeader
 	, putHeader
@@ -43,6 +44,7 @@
 import Data.Word
 import Data.Bits
 import Control.Monad
+import Control.Monad.Identity
 import Control.Applicative ((<|>), (<$>))
 
 data ASN1Class =
@@ -272,3 +274,8 @@
 				[]         -> E.throwError ASN1WritingUnexpectedConstructionEnd
 				True : tl  -> k (Chunks [putEoc]) >>== loop tl
 				False : tl -> k (Chunks []) >>== loop tl
+
+toBytes :: [ASN1Event] -> L.ByteString
+toBytes evs = case runIdentity (run (enumList 8 evs $$ joinI (enumWriteBytes $$ E.consume))) of
+	Left err -> error $ show err
+	Right l  -> L.fromChunks l
diff --git a/Data/ASN1/Stream.hs b/Data/ASN1/Stream.hs
--- a/Data/ASN1/Stream.hs
+++ b/Data/ASN1/Stream.hs
@@ -58,10 +58,16 @@
 	| otherwise = let (ys, zs) = getConstructedEnd (i-1) xs in (x:ys,zs)
 getConstructedEnd i (x:xs)               = let (ys, zs) = getConstructedEnd i xs in (x:ys,zs)
 
-getConstructedEndRepr :: Int -> [ASN1Repr] -> ([ASN1Repr],[ASN1Repr])
-getConstructedEndRepr _ xs@[]                 = (xs, [])
-getConstructedEndRepr i ((x@(Start _, _)):xs) = let (yz, zs) = getConstructedEndRepr (i+1) xs in (x:yz,zs)
-getConstructedEndRepr i ((x@(End _, _)):xs)
-	| i == 0    = ([], xs)
-	| otherwise = let (ys, zs) = getConstructedEndRepr (i-1) xs in (x:ys,zs)
-getConstructedEndRepr i (x:xs)                = let (ys, zs) = getConstructedEndRepr i xs in (x:ys,zs)
+getConstructedEndRepr :: [ASN1Repr] -> ([ASN1Repr],[ASN1Repr])
+getConstructedEndRepr = g
+	where
+		g []                 = ([], [])
+		g (x@(Start _,_):xs) = let (ys, zs) = getEnd 1 xs in (x:ys, zs)
+		g (x:xs)             = ([x],xs)
+
+		getEnd :: Int -> [ASN1Repr] -> ([ASN1Repr],[ASN1Repr])
+		getEnd _ []                    = ([], [])
+		getEnd 0 xs                    = ([], xs)
+		getEnd i ((x@(Start _, _)):xs) = let (ys, zs) = getEnd (i+1) xs in (x:ys,zs)
+		getEnd i ((x@(End _, _)):xs)   = let (ys, zs) = getEnd (i-1) xs in (x:ys,zs)
+		getEnd i (x:xs)                = let (ys, zs) = getEnd i xs in (x:ys,zs)
diff --git a/asn1-data.cabal b/asn1-data.cabal
--- a/asn1-data.cabal
+++ b/asn1-data.cabal
@@ -1,5 +1,5 @@
 Name:                asn1-data
-Version:             0.4.4
+Version:             0.4.5
 Description:
     ASN1 data reader and writer in raw form with supports for high level forms of ASN1 (BER, CER and DER).
     .
