diff --git a/Text/Regex/PDeriv/ByteString/Posix.lhs b/Text/Regex/PDeriv/ByteString/Posix.lhs
--- a/Text/Regex/PDeriv/ByteString/Posix.lhs
+++ b/Text/Regex/PDeriv/ByteString/Posix.lhs
@@ -19,6 +19,10 @@
 >     , regexec
 >     ) where 
 
+
+> import System.IO.Unsafe
+
+
 > import Data.List 
 > import Data.Char (ord)
 > import GHC.Int
@@ -26,6 +30,7 @@
 > import qualified Data.IntMap as IM
 > import qualified Data.ByteString.Char8 as S
 
+
 > import Text.Regex.Base(RegexOptions(..),RegexLike(..),MatchArray)
 
 
@@ -38,6 +43,9 @@
 
 
 
+> logger io = unsafePerformIO io
+
+
 A word is a byte string.
 
 > type Word = S.ByteString
@@ -174,7 +182,10 @@
 >     let rs  = map snd bs
 >         rs' = map snd bs'
 >         os  = map (\ (r,r') -> compareRangeLocal r r')  (zip rs rs')
->     in firstNonEQ os
+>     in {- logger (print (show os)) `seq` 
+>        logger (print (show bs)) `seq` 
+>        logger (print (show bs')) `seq` -}
+>        firstNonEQ os
 
 > compareRangeLocal :: [Range] -> [Range] -> Ordering
 > compareRangeLocal [] [] = EQ
@@ -182,7 +193,8 @@
 >   | (len x) > (len y) = GT
 >   | (len x) == (len y) = compareRangeLocal xs ys
 >   | otherwise = LT
-> compareRangeLocal _ _ = LT
+> compareRangeLocal (_:_) [] = GT
+> compareRangeLocal [] (_:_) = LT
 > {-
 > compareRangeLocal [] _ = LT
 > compareRangeLocal _ [] = GT
@@ -324,8 +336,8 @@
 >     in if null pds then []
 >        else [ (PE (resToRE pds), ( \_ -> id ), [] ) ]
 > pdPat0 (PStar p g) l = let pfs = pdPat0 p l
->                            f'  = resetLocalBnd p -- restart all local binder in variables in p
->                        in [ (PPair p' (PStar p g), (\ i -> (f i) . f'), vs) | (p', f, vs) <- pfs ]
+>                            reset  = resetLocalBnd p -- restart all local binder in variables in p
+>                        in [ (PPair p' (PStar p g), (\ i -> reset . (f i) ), vs) | (p', f, vs) <- pfs ]
 >                      -- in [ (PPlus p' (PStar p), f) | (p', f) <- pfs ]
 > {-
 > pdPat0 (PPlus p1 p2@(PStar _)) l  -- we drop this case since it make difference with the PPair
@@ -467,7 +479,7 @@
 >                       _                            -> error (show (mbPrefixB, mbSubfixB) )
 >         rs = map snd subPatB      
 >     in listToArray (mainB:(map (\r -> case r of { (_:_) -> fromRange (last r) ; [] -> (-1,0) } ) rs))
->     where fromRange (b,e) = (b, e)
+>     where fromRange (b,e) = (b, e-b+1)
 
 > listToArray l = listArray (0,length l-1) l
 
@@ -490,6 +502,7 @@
 > Right r2 = compile defaultCompOpt defaultExecOpt (S.pack "^((a)|(aa))*$")
 > s2 = S.pack "aa"
 
+We should reset after apply f
 
 0: "(xy : ((x : a)|(y: aa)))*"
 
diff --git a/xhaskell-library.cabal b/xhaskell-library.cabal
--- a/xhaskell-library.cabal
+++ b/xhaskell-library.cabal
@@ -1,5 +1,5 @@
 Name:                   xhaskell-library
-Version:                0.0.4
+Version:                0.0.5
 License:                BSD3
 License-File:           LICENSE
 Copyright:              Copyright (c) 2009, Kenny Zhuo Ming Lu and Martin Sulzmann
@@ -40,5 +40,5 @@
                          Text.Regex.PDeriv.Dictionary
   Buildable:              True
   Extensions:             GADTs, MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, TypeSynonymInstances, FlexibleContexts
-  GHC-Options:            -O2 
+  GHC-Options:            
   GHC-Prof-Options:       -auto-all
