diff --git a/sgd.cabal b/sgd.cabal
--- a/sgd.cabal
+++ b/sgd.cabal
@@ -1,5 +1,5 @@
 name:               sgd
-version:            0.3.1
+version:            0.3.2
 synopsis:           Stochastic gradient descent
 description:
     Implementation of a Stochastic Gradient Descent optimization method.
@@ -37,6 +37,7 @@
       , mtl
       , filepath
       , temporary
+      , lazy-io
 
     exposed-modules:
         Numeric.SGD
diff --git a/src/Numeric/SGD/Dataset.hs b/src/Numeric/SGD/Dataset.hs
--- a/src/Numeric/SGD/Dataset.hs
+++ b/src/Numeric/SGD/Dataset.hs
@@ -22,11 +22,11 @@
 import           Data.Binary (Binary, encodeFile, decode)
 import qualified Data.ByteString as B
 import qualified Data.ByteString.Lazy as BL
-import           System.IO.Unsafe (unsafeInterleaveIO)
 import           System.IO.Temp (withTempDirectory)
 import           System.FilePath ((</>))
 import qualified System.Random as R
 import qualified Data.Vector as V
+import qualified Control.Monad.LazyIO as LazyIO
 import qualified Control.Monad.State.Strict as S
 
 
@@ -46,7 +46,7 @@
 
 -- | Lazily load dataset from a disk.
 loadData :: Dataset a -> IO [a]
-loadData Dataset{..} = lazyMapM elemAt [0 .. size - 1]
+loadData Dataset{..} = LazyIO.mapM elemAt [0 .. size - 1]
 
 
 -- | A dataset sample of the given size.
@@ -57,14 +57,6 @@
     let (i, g'') = R.next g'
     x <- dataset `elemAt` (i `mod` size dataset)
     return (x:xs, g'')
-
-
-lazyMapM :: (a -> IO b) -> [a] -> IO [b]
-lazyMapM f (x:xs) = do
-    y <- f x
-    ys <- unsafeInterleaveIO $ lazyMapM f xs
-    return (y:ys)
-lazyMapM _ [] = return []
 
 
 -------------------------------------------
