diff --git a/csound-expression-typed.cabal b/csound-expression-typed.cabal
--- a/csound-expression-typed.cabal
+++ b/csound-expression-typed.cabal
@@ -1,5 +1,5 @@
 Name:          csound-expression-typed
-Version:       0.0.7.2
+Version:       0.0.7.3
 Cabal-Version: >= 1.6
 License:       BSD3
 License-file:  LICENSE
@@ -25,7 +25,7 @@
   Ghc-Options:    -Wall
   Build-Depends:
         base >= 4, base < 5, ghc-prim, containers, transformers >= 0.3, Boolean >= 0.1.0, colour >= 2.0, data-default, deepseq,
-        wl-pprint, stable-maps >= 0.0.3.3, csound-expression-dynamic >= 0.1.3
+        wl-pprint, stable-maps >= 0.0.3.3, csound-expression-dynamic >= 0.1.4
   Hs-Source-Dirs:      src/
   Exposed-Modules:
     Csound.Typed
diff --git a/src/Csound/Typed/Control.hs b/src/Csound/Typed/Control.hs
--- a/src/Csound/Typed/Control.hs
+++ b/src/Csound/Typed/Control.hs
@@ -5,6 +5,8 @@
     module Csound.Typed.Control.SERef,
     -- * Global settings
     instr0, getIns, setDur,
+    -- * Misc
+    freshId,
     -- * Score
     module Csound.Typed.Control.Mix,
     -- * Midi
@@ -22,7 +24,6 @@
 ) where
 
 import Csound.Typed.GlobalState.SE
-
 import Csound.Typed.Control.SERef
 
 import Csound.Typed.Control.Evt
@@ -64,3 +65,7 @@
     setDurationForce dt
     return vals
 
+
+-- | Gets new id.
+freshId :: SE D
+freshId = SE $ fmap fromE freeChn 
diff --git a/src/Csound/Typed/GlobalState.hs b/src/Csound/Typed/GlobalState.hs
--- a/src/Csound/Typed/GlobalState.hs
+++ b/src/Csound/Typed/GlobalState.hs
@@ -3,13 +3,13 @@
     module Csound.Typed.GlobalState.GE,
     module Csound.Typed.GlobalState.SE,
     module Csound.Typed.GlobalState.Instr,
-    module Csound.Typed.GlobalState.Cache,
-    -- * Reexports dynamic
+    module Csound.Typed.GlobalState.Cache,    
+    -- * Reexports dynamic    
     BandLimited(..), readBandLimited, renderBandLimited,
     Instrs(..), IdMap(..), getInstrIds,
-    getIn, chnUpdateUdo, renderGlobals, turnoff, turnoff2, exitnow,
+    getIn, chnUpdateUdo, renderGlobals, turnoff, turnoff2, exitnow, 
     oscListen, oscInit, oscSend,
-    chnSet, chnGet, 
+    chnSet, chnGet, freeChn,
     readChnEvtLoop,
     masterUpdateChnAlive,
     servantUpdateChnAlive,
diff --git a/src/Csound/Typed/GlobalState/Elements.hs b/src/Csound/Typed/GlobalState/Elements.hs
--- a/src/Csound/Typed/GlobalState/Elements.hs
+++ b/src/Csound/Typed/GlobalState/Elements.hs
@@ -3,7 +3,7 @@
     -- * Identifiers
     IdMap(..), saveId, newIdMapId,
     -- ** Gens
-    GenMap, newGen, newGenId,
+    GenMap, newGen, newGenId, nextGlobalGenCounter,
     -- Sf2
     SfFluid(..), SfSpec(..), SfMap, newSf, sfVar, renderSf,
     -- ** Band-limited waveforms
@@ -82,6 +82,11 @@
 
 newString :: String -> State StringMap Prim
 newString = fmap PrimInt . saveId
+
+-- gen counter
+
+nextGlobalGenCounter :: State Int Int
+nextGlobalGenCounter = state $ \s -> (s, s + 1)
 
 -- sf
 
diff --git a/src/Csound/Typed/GlobalState/GE.hs b/src/Csound/Typed/GlobalState/GE.hs
--- a/src/Csound/Typed/GlobalState/GE.hs
+++ b/src/Csound/Typed/GlobalState/GE.hs
@@ -14,7 +14,7 @@
     -- * Notes
     addNote,
     -- * GEN routines
-    saveGen,
+    saveGen, getNextGlobalGenId,
     -- * Sf2
     saveSf, sfTable,
     -- * Band-limited waves
@@ -82,6 +82,7 @@
     
 data History = History
     { genMap            :: GenMap
+    , globalGenCounter  :: Int
     , stringMap         :: StringMap
     , sfMap             :: SfMap
     , midiMap           :: MidiMap GE
@@ -98,7 +99,7 @@
     , guis              :: Guis }
 
 instance Default History where
-    def = History def def def def def def def def def def def (return ()) def def def
+    def = History def def def def def def def def def def def def (return ()) def def def
 
 data Msg = Msg
 data MidiAssign = MidiAssign MidiType Channel InstrId
@@ -150,6 +151,9 @@
 saveStr :: String -> GE E
 saveStr = fmap prim . onStringMap . newString
     where onStringMap = onHistory stringMap (\val h -> h{ stringMap = val })
+
+getNextGlobalGenId :: GE Int
+getNextGlobalGenId = onHistory globalGenCounter (\a h -> h{ globalGenCounter = a }) nextGlobalGenCounter
 
 saveGen :: Gen -> GE E
 saveGen = onGenMap . newGen
diff --git a/src/Csound/Typed/GlobalState/Opcodes.hs b/src/Csound/Typed/GlobalState/Opcodes.hs
--- a/src/Csound/Typed/GlobalState/Opcodes.hs
+++ b/src/Csound/Typed/GlobalState/Opcodes.hs
@@ -1,7 +1,7 @@
 module Csound.Typed.GlobalState.Opcodes(
     sprintf,
-    -- * channel opcodes
-    ChnRef(..), chnRefFromParg, chnRefAlloc, readChn, writeChn, 
+    -- * channel opcodes    
+    ChnRef(..), chnRefFromParg, chnRefAlloc, readChn, writeChn, freeChn,
     readChnEvtLoop,
     chnUpdateUdo, masterUpdateChnAlive, servantUpdateChnAlive,
     masterUpdateChnRetrig, servantUpdateChnRetrig,
diff --git a/src/Csound/Typed/Types.hs b/src/Csound/Typed/Types.hs
--- a/src/Csound/Typed/Types.hs
+++ b/src/Csound/Typed/Types.hs
@@ -10,7 +10,10 @@
     -- * Tuples
     module Csound.Typed.Types.Tuple,        
     -- * Events
-    module Csound.Typed.Types.Evt
+    module Csound.Typed.Types.Evt,
+
+    -- * Tab helpers
+    getNextGlobalGenId
 ) where
 
 import qualified Csound.Dynamic as D
@@ -20,7 +23,12 @@
 import Csound.Typed.Types.Evt
 import Csound.Typed.Types.Lift
 
-import Csound.Typed.GlobalState(evalSE, SE)
+import Csound.Typed.GlobalState(evalSE, SE, geToSe)
+
+import qualified Csound.Typed.GlobalState as G(getNextGlobalGenId)
+
+getNextGlobalGenId :: SE Int
+getNextGlobalGenId = geToSe G.getNextGlobalGenId
 
 -- appends inits
 
diff --git a/src/Csound/Typed/Types/Prim.hs b/src/Csound/Typed/Types/Prim.hs
--- a/src/Csound/Typed/Types/Prim.hs
+++ b/src/Csound/Typed/Types/Prim.hs
@@ -395,7 +395,7 @@
         elseIfs as
         elseBegin 
         el
-        foldl1 (>>) $ replicate (1 + length bodies) ifEnd
+        foldl1 (>>) $ replicate (length bodies) ifEnd
     where elseIfs = mapM_ (\(p, body) -> elseBegin >> ifBegin p >> body)
 
 ifBegin :: BoolSig -> SE ()
