diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
 # Revision history for minilight
 
+## 0.5.0 -- 2020-05-06
+
+* `runMiniloop` with initial state in monad
+
 ## 0.4.4 -- 2020-05-05
 
 * Add `registerComponent` and `extend9tiles` functions
diff --git a/examples/boids.hs b/examples/boids.hs
--- a/examples/boids.hs
+++ b/examples/boids.hs
@@ -119,5 +119,5 @@
                   , componentResolver    = resolver
                   }
       )
-      (Game {objects = objs, pic = pic})
+      (return $ Game {objects = objs, pic = pic})
       (execStateT mainloop)
diff --git a/examples/button-counter.hs b/examples/button-counter.hs
--- a/examples/button-counter.hs
+++ b/examples/button-counter.hs
@@ -38,16 +38,15 @@
   return $ Button {font = font, counter = 0}
 
 main :: IO ()
-main = do
-  runLightT $ do
-    uid    <- newUID
-    button <- newComponent uid =<< new
+main = runLightT $ do
+  uid    <- newUID
+  button <- newComponent uid =<< new
 
-    runMiniloop
-      ( defConfig { appConfigFile        = Nothing
-                  , additionalComponents = [button]
-                  , componentResolver    = resolver
-                  }
-      )
-      ()
-      return
+  runMiniloop
+    ( defConfig { appConfigFile        = Nothing
+                , additionalComponents = [button]
+                , componentResolver    = resolver
+                }
+    )
+    (return ())
+    return
diff --git a/minilight.cabal b/minilight.cabal
--- a/minilight.cabal
+++ b/minilight.cabal
@@ -3,7 +3,7 @@
 --   For further documentation, see http://haskell.org/cabal/users-guide/
 
 name:                minilight
-version:             0.4.4
+version:             0.5.0
 synopsis:            A SDL2-based graphics library, batteries-included.
 description:
   This package provides the wheel for a graphical application or a game.
diff --git a/src/MiniLight.hs b/src/MiniLight.hs
--- a/src/MiniLight.hs
+++ b/src/MiniLight.hs
@@ -83,8 +83,8 @@
         else withSDL . withWindow . (\f w -> f (Just w))
       )
     $ \mwindow -> do
-        renderer <- flip mapM mwindow $ \window -> do
-          SDL.createRenderer window (-1) SDL.defaultRenderer
+        renderer <- forM mwindow
+          $ \window -> SDL.createRenderer window (-1) SDL.defaultRenderer
         fc     <- loadFontCache
         logger <- liftIO $ logQueue conf (logLevel conf)
         runReaderT (runLightT' prog)
@@ -217,7 +217,7 @@
 
 
 -- | Same as 'runMainloop' but fixing the type.
-runMiniloop :: LoopConfig -> s -> (s -> MiniLoop s) -> MiniLight ()
+runMiniloop :: LoopConfig -> MiniLoop s -> (s -> MiniLoop s) -> MiniLight ()
 runMiniloop = runMainloop LoopState
 
 -- | Run a mainloop.
@@ -234,7 +234,7 @@
      )
   => (env -> LoopEnv -> LoaderEnv -> env')  -- ^ Environment conversion
   -> LoopConfig  -- ^ Loop config
-  -> s  -- ^ Initial state
+  -> LightT env' m s  -- ^ Initial monad generating initial state
   -> (s -> LightT env' m s)  -- ^ A function called in every loop
   -> LightT env m ()
 runMainloop conv conf initial userloop = do
@@ -249,8 +249,9 @@
     (LoaderEnv {registry = reg, tagRegistry = tag, appConfig = conf})
     initial
  where
-  run loop loader s = do
+  run loop loader ms = do
     setup loop loader
+    s <- envLightT (\env -> conv env loop loader) ms
     go loop loader s
 
   setup loop loader = envLightT (\env -> conv env loop loader) $ do
