stepApp :: AppVar a -> IO ()
stepApp mvar = do
    app <- readMVar mvar
    case _window app of
        Just win -> do
            t      <- getTime
            input' <- getInput win $ _userInput app

            let clock'     = tickClock t $ _clock app
                userData'  = (app^.userApp.onInput) input' $ app^.userApp.userData
                app'       = app { _clock     = clock'
                                 , _userInput = input'
                                 }

            userData'' <- (app^.userApp.onStep) clock' userData'
            let app'' = app' & userApp.userData .~ userData''
            swapMVar mvar app'' 
            renderUserApp win $ app''^.userApp

            when ((app^.userApp.shouldQuit) userData'') $ 
                (app^.userApp.onQuit) userData''
            return ()

        Nothing -> do putStrLn "Window is nothing, quitting."
                      app^.userApp.onQuit $ app^.userApp.userData
                      void shutdown
stepApp :: AppVar a -> IO ()
stepApp mvar = do
    app <- readMVar mvar
    case _window app of
        Just win -> do
            t      <- getTime
            input' <- getInput win $ _userInput app

            let clock'     = tickClock t $ _clock app
                userData'  = (app^.userApp.onInput) input' $ app^.userApp.userData
                app'       = app { _clock     = clock'
                                 , _userInput = input'
                                 }

            userData'' <- (app^.userApp.onStep) clock' userData'
            let app'' = app' & userApp.userData .~ userData''
            swapMVar mvar app'' 
            renderUserApp win $ app''^.userApp

            when ((app^.userApp.shouldQuit) userData'') $ 
                (app^.userApp.onQuit) userData''
            return ()

        Nothing -> do putStrLn "Window is nothing, quitting."
                      app^.userApp.onQuit $ app^.userApp.userData
                      void shutdown
stepApp mvar = do
    app <- readMVar mvar
    case _window app of
        Just win -> do
            t      <- getTime
            input' <- getInput win $ _userInput app

            let clock'     = tickClock t $ _clock app
                userData'  = (app^.userApp.onInput) input' $ app^.userApp.userData
                app'       = app { _clock     = clock'
                                 , _userInput = input'
                                 }

            userData'' <- (app^.userApp.onStep) clock' userData'
            let app'' = app' & userApp.userData .~ userData''
            swapMVar mvar app'' 
            renderUserApp win $ app''^.userApp

            when ((app^.userApp.shouldQuit) userData'') $ 
                (app^.userApp.onQuit) userData''
            return ()

        Nothing -> do putStrLn "Window is nothing, quitting."
                      app^.userApp.onQuit $ app^.userApp.userData
                      void shutdown