diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp
index 0543fe2..54dbffc 100644
--- a/libretro/libretro.cpp
+++ b/libretro/libretro.cpp
@@ -104,7 +104,7 @@ void retro_init(void)
 void retro_reset(void)
 {
    if(lynx){
-       lynx->SaveEEPROM();
+      lynx->SaveEEPROM();
       lynx->Reset();
    }
 }
@@ -115,9 +115,8 @@ void retro_deinit(void)
    initialized = false;
 
    if(lynx){
-       lynx->SaveEEPROM();
       delete lynx;
-       lynx=0;
+      lynx=0;
    }
 }
 
@@ -207,11 +206,21 @@ void retro_run(void)
    newFrame = false;
 }
 
-static void gettempfilename(char *dest)
+static void gettempfilename(char *dest, size_t len)
 {
+#if 0
    const char *dir = 0;
    environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir);
    sprintf(dest, "%s%chandy.tmp", dir, SLASH_STR);
+#endif
+
+#ifdef WIN32
+   GetTempFileName(GetTempPath(), "hnd", 0, dest);
+#else
+   char *tmp = tempnam(0, "handy");
+   strncpy(dest, tmp, len);
+   free(tmp);
+#endif
 }
 
 size_t retro_serialize_size(void)
@@ -220,7 +229,7 @@ size_t retro_serialize_size(void)
    if(!lynx)
       return 0;
 
-   gettempfilename(tempfilename);
+   gettempfilename(tempfilename,1024);
    return lynx->MemoryContextSave(tempfilename, NULL);
 }
 
@@ -230,7 +239,7 @@ bool retro_serialize(void *data, size_t size)
    if(!lynx)
       return false;
 
-   gettempfilename(tempfilename);
+   gettempfilename(tempfilename,1024);
    return lynx->MemoryContextSave(tempfilename, (char*)data) > 0;
 }
 
@@ -306,14 +315,9 @@ static bool lynx_initialize_system(const char* gamepath)
    ULONG rot;
    char romfilename[1024];
    struct retro_variable var = {0};
-   if(lynx){
-       lynx->SaveEEPROM();
-      delete lynx;
-      lynx=0;
-   }
 
+   retro_deinit();
    lynx_romfilename(romfilename);
-
    lynx = new CSystem(gamepath, romfilename, true);
 
    rot = MIKIE_NO_ROTATE;
@@ -388,13 +392,7 @@ bool retro_load_game_special(unsigned, const struct retro_game_info*, size_t)
 
 void retro_unload_game(void)
 {
-// TODO should be save EEPROM here, too?
-//    if(lynx){
-//        lynx->SaveEEPROM();
-//        delete lynx;
-//        lynx=0;
-//    }
-   initialized = false;
+   retro_deinit();
 }
 
 void retro_cheat_reset(void)
diff --git a/lynx/c65c02.h b/lynx/c65c02.h
index 086a8ca..08fcadd 100644
--- a/lynx/c65c02.h
+++ b/lynx/c65c02.h
@@ -137,7 +137,7 @@ typedef struct
 class C65C02
 {
    public:
-      C65C02(CSystemBase& parent)
+      explicit C65C02(CSystemBase& parent)
          :mSystem(parent)
       {
          TRACE_CPU0("C65C02()");
diff --git a/lynx/cart.cpp b/lynx/cart.cpp
index 6e42d02..2516ff9 100644
--- a/lynx/cart.cpp
+++ b/lynx/cart.cpp
@@ -68,6 +68,10 @@ CCart::CCart(UBYTE *gamedata,ULONG gamesize)
    mEEPROMType=0;
    mCRC32=0;
    mCRC32=crc32(mCRC32,gamedata,gamesize);
+   mCounter=0;
+   mShifter=0;
+   mAddrData=0;
+   mStrobe=0;
 
    // Open up the file
 
diff --git a/lynx/eeprom.cpp b/lynx/eeprom.cpp
index 7b888fc..1d17d9a 100644
--- a/lynx/eeprom.cpp
+++ b/lynx/eeprom.cpp
@@ -14,6 +14,11 @@ CEEPROM::CEEPROM()
 {
    type=0;
    *filename=0;
+   ADDR_MASK=0;
+   CMD_BITS=0;
+   ADDR_BITS=0;
+   DONE_MASK=0;
+   mAUDIN_ext=0;
    Reset();
 }
 
diff --git a/lynx/lynxdec.cpp b/lynx/lynxdec.cpp
index 051e737..a1e4b64 100644
--- a/lynx/lynxdec.cpp
+++ b/lynx/lynxdec.cpp
@@ -240,7 +240,7 @@ int decrypt_frame(unsigned char * result,
       const unsigned char * public_mod,
       const int length)
 {
-   int i, j;
+   int i;
    int blocks;
    int accumulator;
    unsigned char* rptr = result;
@@ -279,11 +279,10 @@ void lynx_decrypt(unsigned char * result,
       const unsigned char * encrypted,
       const int length)
 {
-   int blocks = 0;
    int read_index = 0;
 
    /* decrypt the first frame of encrypted data */
-   blocks = decrypt_frame(&result[0],
+   /* int blocks = */decrypt_frame(&result[0],
          &encrypted[read_index],
          /* lynx_public_exp */ 0,
          lynx_public_mod,
diff --git a/lynx/memmap.h b/lynx/memmap.h
index 5d450b8..b220905 100644
--- a/lynx/memmap.h
+++ b/lynx/memmap.h
@@ -69,7 +69,7 @@ class CMemMap : public CLynxBase
    // Function members
 
    public:
-      CMemMap(CSystem& parent);
+      explicit CMemMap(CSystem& parent);
 
    public:
       bool	ContextSave(FILE *fp);
diff --git a/lynx/mikie.cpp b/lynx/mikie.cpp
index 0ab502b..70bd9de 100644
--- a/lynx/mikie.cpp
+++ b/lynx/mikie.cpp
@@ -69,8 +69,8 @@ void CMikie::BlowOut(void)
 }
 
 
-   CMikie::CMikie(CSystem& parent)
-:mSystem(parent)
+CMikie::CMikie(CSystem& parent)
+  :mSystem(parent)
 {
    TRACE_MIKIE0("CMikie()");
 
@@ -90,6 +90,10 @@ void CMikie::BlowOut(void)
    for(loop=0;loop<16;loop++) mPalette[loop].Index=loop;
    for(loop=0;loop<4096;loop++) mColourMap[loop]=0;
 
+   mUART_TX_CALLBACK_OBJECT=0;
+   memset(mUART_Rx_input_queue,0,sizeof(mUART_Rx_input_queue));
+   mDisplayPitch=0;
+
    Reset();
 }
 
@@ -2790,7 +2794,7 @@ inline void CMikie::Update(void)
             }
             else
             {
-               if(gCPUWakeupTime>gSystemCycleCount) gNextTimerEvent=gCPUWakeupTime;
+               gNextTimerEvent=gCPUWakeupTime;
             }
          }
 
diff --git a/lynx/mikie.h b/lynx/mikie.h
index d1f1b6f..7a6fc42 100644
--- a/lynx/mikie.h
+++ b/lynx/mikie.h
@@ -183,7 +183,7 @@ enum
 class CMikie : public CLynxBase
 {
    public:
-      CMikie(CSystem& parent);
+      explicit CMikie(CSystem& parent);
       ~CMikie();
 
       bool	ContextSave(FILE *fp);
diff --git a/lynx/ram.cpp b/lynx/ram.cpp
index fb101c4..9df4e50 100644
--- a/lynx/ram.cpp
+++ b/lynx/ram.cpp
@@ -77,7 +77,7 @@ CRam::CRam(UBYTE *filememory,ULONG filesize)
    }
    else
    {
-      filememory=NULL;
+      mFileData=NULL;
    }
    // Reset will cause the loadup
 
@@ -86,10 +86,9 @@ CRam::CRam(UBYTE *filememory,ULONG filesize)
 
 CRam::~CRam()
 {
-   if(mFileSize)
+   if(mFileData)
    {
       delete[] mFileData;
-      mFileData=NULL;
    }
 }
 
diff --git a/lynx/rom.cpp b/lynx/rom.cpp
index 14df80d..d400118 100644
--- a/lynx/rom.cpp
+++ b/lynx/rom.cpp
@@ -95,7 +95,7 @@ CRom::CRom(const char *romfile,bool useEmu)
             fprintf(stdout, "The Lynx Boot ROM image couldn't be loaded! Using built-in replacement\n");
             mValid = FALSE;
          }
-         if(fp) fclose(fp);
+         fclose(fp);
       }
 
       // Check the code that has been loaded and report an error if its a
diff --git a/lynx/susie.cpp b/lynx/susie.cpp
index 7a235c3..6cf2f2b 100644
--- a/lynx/susie.cpp
+++ b/lynx/susie.cpp
@@ -74,6 +74,15 @@ ULONG cycles_used=0;
 CSusie::CSusie(CSystem& parent) :mSystem(parent)
 {
    TRACE_SUSIE0("CSusie()");
+   mLineType=0;
+   mLineShiftRegCount=0;
+   mLineShiftReg=0;
+   mLineRepeatCount=0;
+   mLinePixel=0;
+   mLinePacketBitsLeft=0;
+   mCollision=0;
+   mLineBaseAddress=0;
+   mLineCollisionAddress=0;
    Reset();
 }
 
diff --git a/lynx/susie.h b/lynx/susie.h
index 4a6a891..24163cb 100644
--- a/lynx/susie.h
+++ b/lynx/susie.h
@@ -333,7 +333,7 @@ typedef struct
 class CSusie : public CLynxBase
 {
    public:
-      CSusie(CSystem& parent);
+      explicit CSusie(CSystem& parent);
       ~CSusie();
 
       void	Reset(void);
diff --git a/lynx/system.cpp b/lynx/system.cpp
index 1b01e78..fd90e71 100644
--- a/lynx/system.cpp
+++ b/lynx/system.cpp
@@ -121,15 +121,15 @@ void _splitpath(const char* path, char* drv, char* dir, char* name, char* ext)
    }
 }
 
-   CSystem::CSystem(const char* gamefile, const char* romfile, bool useEmu)
-:mCart(NULL),
+CSystem::CSystem(const char* gamefile, const char* romfile, bool useEmu)
+  :mCart(NULL),
    mRom(NULL),
    mMemMap(NULL),
    mRam(NULL),
    mCpu(NULL),
    mMikie(NULL),
-    mSusie(NULL),
-    mEEPROM(NULL)
+   mSusie(NULL),
+   mEEPROM(NULL)
 {
 
 #ifdef _LYNXDBG
@@ -147,8 +147,6 @@ void _splitpath(const char* path, char* drv, char* dir, char* name, char* ext)
    if(strcmp(gamefile,"")==0)
    {
       // No file
-      filesize=0;
-      filememory=NULL;
    }
    else
    {
@@ -165,19 +163,19 @@ void _splitpath(const char* path, char* drv, char* dir, char* name, char* ext)
       fseek(fp,0,SEEK_END);
       filesize=ftell(fp);
       fseek(fp,0,SEEK_SET);
-      filememory=(UBYTE*) new UBYTE[filesize];
+      filememory=new UBYTE[filesize];
 
       if(fread(filememory,sizeof(char),filesize,fp)!=filesize)
       {
          fprintf(stderr, "Invalid Cart (filesize).\n");
-         delete filememory;
+         filesize=0;
       }
 
       fclose(fp);
    }
 
    // Now try and determine the filetype we have opened
-   if(filesize)
+   if(filesize>10)
    {
       char clip[11];
       memcpy(clip,filememory,11);
@@ -191,9 +189,9 @@ void _splitpath(const char* path, char* drv, char* dir, char* name, char* ext)
       {
          fprintf(stderr, "Invalid Cart (type). but 128/256/512k size -> set to RAW and try to load raw rom image\n");
          mFileType=HANDY_FILETYPE_RAW;
-         //delete filememory;// WHY????? -> crash!
       }else{
          fprintf(stderr, "Invalid Cart (type). -> set to RAW and try to load raw rom image\n");
+         mFileType=HANDY_FILETYPE_RAW;
       }
    }
 
@@ -228,20 +226,18 @@ void _splitpath(const char* path, char* drv, char* dir, char* name, char* ext)
             if((fp=fopen(cartgo,"rb"))==NULL)
             {
                fprintf(stderr, "Invalid Cart.\n");
-               delete filememory;
             }
 
             // How big is the file ??
             fseek(fp,0,SEEK_END);
             howardsize=ftell(fp);
             fseek(fp,0,SEEK_SET);
-            howardmemory=(UBYTE*) new UBYTE[filesize];
+            howardmemory=new UBYTE[filesize];
 
             if(fread(howardmemory,sizeof(char),howardsize,fp)!=howardsize)
             {
-               delete howardmemory;
                fprintf(stderr, "Invalid Cart.\n");
-               delete filememory;
+               howardsize=0;
             }
 
             fclose(fp);
@@ -294,8 +290,8 @@ void _splitpath(const char* path, char* drv, char* dir, char* name, char* ext)
          fprintf(stderr, "Invalid Snapshot.\n");
       }
    }
-   if(filesize) delete filememory;
-   if(howardsize) delete howardmemory;
+   if(filememory) delete[] filememory;
+   if(howardmemory) delete[] howardmemory;
    mEEPROM->SetEEPROMType(mCart->mEEPROMType);
 
    {
@@ -415,7 +411,6 @@ void CSystem::Reset(void)
    gSystemIRQ=FALSE;
    gSystemNMI=FALSE;
    gSystemCPUSleep=FALSE;
-   gSystemHalt=FALSE;
 
    gThrottleLastTimerCount=0;
    gThrottleNextCycleCheckpoint=0;
@@ -429,6 +424,8 @@ void CSystem::Reset(void)
 
 #ifdef _LYNXDBG
    gSystemHalt=TRUE;
+#else
+   gSystemHalt=FALSE;
 #endif
 
    mMemMap->Reset();
@@ -520,8 +517,8 @@ bool CSystem::ContextSave(const char *context)
    // Save other device contexts
    if(!mMemMap->ContextSave(fp)) status=0;
    if(!mCart->ContextSave(fp)) status=0;
-   if(!mEEPROM->ContextSave(fp)) status=0;
-   //	if(!mRom->ContextSave(fp)) status=0; We no longer save the system ROM
+   //if(!mEEPROM->ContextSave(fp)) status=0;
+   //if(!mRom->ContextSave(fp)) status=0; We no longer save the system ROM
    if(!mRam->ContextSave(fp)) status=0;
    if(!mMikie->ContextSave(fp)) status=0;
    if(!mSusie->ContextSave(fp)) status=0;
@@ -537,6 +534,7 @@ size_t	CSystem::MemoryContextSave(const char* tmpfilename, char *context)
 
    if(!ContextSave(tmpfilename))
    {
+      remove(tmpfilename);
       return 0;
    }
 
@@ -555,7 +553,7 @@ size_t	CSystem::MemoryContextSave(const char* tmpfilename, char *context)
 
    if(NULL == context)
    {
-      filememory = (UBYTE*) new UBYTE[filesize];
+      filememory = new UBYTE[filesize];
    }
    else
    {
@@ -571,11 +569,10 @@ size_t	CSystem::MemoryContextSave(const char* tmpfilename, char *context)
 
    if(NULL == context)
    {
-      delete filememory;
+      delete[] filememory;
    }
 
    remove(tmpfilename);
-
    return ret;
 }
 
@@ -683,17 +680,19 @@ bool CSystem::ContextLoad(const char *context)
    {
       FILE *fp;
       // Just open an read into memory
-      if((fp=fopen(context,"rb"))==NULL) status=0;
+      if((fp=fopen(context,"rb"))==NULL)
+         return 0;
 
       fseek(fp,0,SEEK_END);
       filesize=ftell(fp);
       fseek(fp,0,SEEK_SET);
-      filememory=(UBYTE*) new UBYTE[filesize];
+      filememory=new UBYTE[filesize];
 
       if(fread(filememory,sizeof(char),filesize,fp)!=filesize)
       {
          fclose(fp);
-         return 1;
+         delete[] filememory;
+         return 0;
       }
       fclose(fp);
    }
@@ -724,7 +723,7 @@ bool CSystem::ContextLoad(const char *context)
          if(mCart->CRC32()!=checksum)
          {
             delete fp;
-            delete filememory;
+            delete[] filememory;
             fprintf(stderr, "[handy]LSS Snapshot CRC does not match the loaded cartridge image, aborting load.\n");
             return 0;
          }
@@ -782,7 +781,7 @@ bool CSystem::ContextLoad(const char *context)
    }
 
    delete fp;
-   delete filememory;
+   delete[] filememory;
 
    return status;
 }
@@ -794,7 +793,7 @@ void CSystem::DebugTrace(int address)
    char message[1024+1];
    int count=0;
 
-   sprintf(message,"%08x - DebugTrace(): ",gSystemCycleCount);
+   sprintf(message,"%08lx - DebugTrace(): ",gSystemCycleCount);
    count=strlen(message);
 
    if(address)
