nsertEvent dbi g@(GUIEvent mtpType start dur state) =
    case mtpType of
        Machine mid -> case ((length $ db_machinebuffer dbi) >= bufferlimit) of
            True  -> do
                --putStrLn "inserting Machine events"
                insertMachineState dbi
            False -> return dbi {
                db_machinebuffer = (mid,start,dur,state) : db_machinebuffer dbi
                }
        Process mid pid -> case ((length $ db_processbuffer dbi) >= bufferlimit) of
            True  -> do
                --putStrLn "inserting Process events"
                insertProcessState dbi
            False -> return dbi {
                db_processbuffer = (mid,pid,start,dur,state) : db_processbuffer dbi
                }
        Thread  mid tid -> case ((length $ db_threadbuffer dbi) >= bufferlimit) of
            True  -> do
                --putStrLn "inserting Thread events"
                insertThreadState dbi
            False -> return dbi {
                db_threadbuffer = (mid,tid,start,dur,state) : db_threadbuffer dbi
                }

insertEvent dbi g@(GUIEvent mtpType start dur state) =
    case mtpType of
        Machine mid -> case ((length $ db_machinebuffer dbi) >= bufferlimit) of
            True  -> do
                --putStrLn "inserting Machine events"
                insertMachineState dbi
            False -> return dbi {
                db_machinebuffer = (mid,start,dur,state) : db_machinebuffer dbi
                }
        Process mid pid -> case ((length $ db_processbuffer dbi) >= bufferlimit) of
            True  -> do
                --putStrLn "inserting Process events"
                insertProcessState dbi
            False -> return dbi {
                db_processbuffer = (mid,pid,start,dur,state) : db_processbuffer dbi
                }
        Thread  mid tid -> case ((length $ db_threadbuffer dbi) >= bufferlimit) of
            True  -> do
                --putStrLn "inserting Thread events"
                insertThreadState dbi
            False -> return dbi {
                db_threadbuffer = (mid,tid,start,dur,state) : db_threadbuffer dbi
                }
insertEvent dbi g@(GUIEvent mtpType start dur state) =
    case mtpType of
        Machine mid -> case ((length $ db_machinebuffer dbi) >= bufferlimit) of
            True  -> do
                --putStrLn "inserting Machine events"
                insertMachineState dbi
            False -> return dbi {
                db_machinebuffer = (mid,start,dur,state) : db_machinebuffer dbi
                }
        Process mid pid -> case ((length $ db_processbuffer dbi) >= bufferlimit) of
            True  -> do
                --putStrLn "inserting Process events"
                insertProcessState dbi
            False -> return dbi {
                db_processbuffer = (mid,pid,start,dur,state) : db_processbuffer dbi
                }
        Thread  mid tid -> case ((length $ db_threadbuffer dbi) >= bufferlimit) of
            True  -> do
                --putStrLn "inserting Thread events"
                insertThreadState dbi
            False -> return dbi {
                db_threadbuffer = (mid,tid,start,dur,state) : db_threadbuffer dbi
                }