Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4/HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4.csproj
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4/HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4.csproj	(revision 6100)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4/HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4.csproj	(revision 6101)
@@ -58,10 +58,7 @@
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="SlaveCommListener.cs" />
   </ItemGroup>
   <ItemGroup>
-    <ProjectReference Include="..\HeuristicLab.Clients.Hive.Slave.Tests\HeuristicLab.Clients.Hive.Slave.Tests-3.4.csproj">
-      <Project>{C4CBD11E-1B83-464A-B0AD-0DC0FF7E57AA}</Project>
-      <Name>HeuristicLab.Clients.Hive.Slave.Tests-3.4</Name>
-    </ProjectReference>
     <ProjectReference Include="..\HeuristicLab.Clients.Hive.Slave\3.4\HeuristicLab.Clients.Hive.Slave-3.4.csproj">
       <Project>{989FE92B-484E-41EE-87E2-6A24AF0381D8}</Project>
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4/Program.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4/Program.cs	(revision 6100)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4/Program.cs	(revision 6101)
@@ -22,5 +22,5 @@
 using System;
 using System.Threading;
-using HeuristicLab.Clients.Hive.SlaveCore.Tests;
+
 
 
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4/SlaveCommListener.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4/SlaveCommListener.cs	(revision 6101)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4/SlaveCommListener.cs	(revision 6101)
@@ -0,0 +1,87 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.ServiceModel;
+using System.Threading;
+using HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts;
+
+namespace HeuristicLab.Clients.Hive.SlaveCore.ConsoleClient {
+
+  /// <summary>
+  /// mock a client, simply print out messages
+  /// </summary>
+  [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
+  public class SlaveCommListener : ISlaveCommunicationCallbacks, IDisposable {
+    ISlaveCommunication pipeProxy;
+    DuplexChannelFactory<ISlaveCommunication> pipeFactory;
+
+    public void Open() {
+      pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(this, "SlaveCommunicationServiceEndpoint");
+
+      while (!ReconnectToSlaveCore()) {
+        Thread.Sleep(700);
+      }
+    }
+
+    public bool ReconnectToSlaveCore() {
+      try {
+        pipeProxy = pipeFactory.CreateChannel();
+        pipeProxy.Subscribe();
+        return true;
+      }
+      catch (Exception e) {
+        OnMessageLogged("Couldn't connect to Slave Core. Waiting for the Core to start.");
+        return false;
+      }
+    }
+
+    public void Close() {
+      if (pipeFactory.State != CommunicationState.Closed &&
+          pipeFactory.State != CommunicationState.Closing &&
+          pipeFactory.State != CommunicationState.Faulted) {
+        pipeProxy.Unsubscribe();
+      }
+      try {
+        pipeFactory.Close();
+      }
+      catch (Exception) {
+        pipeFactory.Abort();
+      }
+    }
+
+    public void OnStatusChanged(SlaveCore.StatusCommons status) {
+      System.Console.WriteLine("SlaveCommListener: " + status);
+    }
+
+    public void OnMessageLogged(string message) {
+      System.Console.WriteLine("SlaveCommListener: " + message);
+    }
+
+    public void OnShutdown() {
+      System.Console.WriteLine("SlaveCommListner: Slave quit");
+    }
+
+    public void Dispose() {
+      Close();
+    }
+  }
+}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/HeuristicLab.Clients.Hive.Slave.Tests-3.4.csproj
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/HeuristicLab.Clients.Hive.Slave.Tests-3.4.csproj	(revision 6100)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/HeuristicLab.Clients.Hive.Slave.Tests-3.4.csproj	(revision 6101)
@@ -66,7 +66,4 @@
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="ALGLIB-2.5.0">
-      <HintPath>C:\Program Files\HeuristicLab 3.3\ALGLIB-2.5.0.dll</HintPath>
-    </Reference>
     <Reference Include="ALGLIB-3.1.0">
       <HintPath>C:\Program Files\HeuristicLab 3.3\ALGLIB-3.1.0.dll</HintPath>
@@ -74,7 +71,4 @@
     <Reference Include="Google.ProtocolBuffers-0.9.1">
       <HintPath>C:\Program Files\HeuristicLab 3.3\Google.ProtocolBuffers-0.9.1.dll</HintPath>
-    </Reference>
-    <Reference Include="HeuristicLab.ALGLIB-2.5.0">
-      <HintPath>C:\Program Files\HeuristicLab 3.3\HeuristicLab.ALGLIB-2.5.0.dll</HintPath>
     </Reference>
     <Reference Include="HeuristicLab.ALGLIB-3.1.0">
@@ -347,8 +341,11 @@
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Mocks\MockServiceLocator.cs" />
-    <Compile Include="SlaveCommListener.cs" />
     <Compile Include="SlaveTest.cs" />
   </ItemGroup>
   <ItemGroup>
+    <ProjectReference Include="..\HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4\HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4.csproj">
+      <Project>{464D70B8-2D91-485C-B622-22E4A4891C68}</Project>
+      <Name>HeuristicLab.Clients.Hive.Slave.ConsoleClient-3.4</Name>
+    </ProjectReference>
     <ProjectReference Include="..\HeuristicLab.Clients.Hive.Slave\3.4\HeuristicLab.Clients.Hive.Slave-3.4.csproj">
       <Project>{989FE92B-484E-41EE-87E2-6A24AF0381D8}</Project>
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/SlaveCommListener.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/SlaveCommListener.cs	(revision 6100)
+++ 	(revision )
@@ -1,87 +1,0 @@
-﻿#region License Information
-/* HeuristicLab
- * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
- *
- * This file is part of HeuristicLab.
- *
- * HeuristicLab is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * HeuristicLab is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
- */
-#endregion
-
-using System;
-using System.ServiceModel;
-using System.Threading;
-using HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts;
-
-namespace HeuristicLab.Clients.Hive.SlaveCore.Tests {
-
-  /// <summary>
-  /// mock a client, simply print out messages
-  /// </summary>
-  [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
-  public class SlaveCommListener : ISlaveCommunicationCallbacks, IDisposable {
-    ISlaveCommunication pipeProxy;
-    DuplexChannelFactory<ISlaveCommunication> pipeFactory;
-
-    public void Open() {
-      pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(this, "SlaveCommunicationServiceEndpoint");
-
-      while (!ReconnectToSlaveCore()) {
-        Thread.Sleep(500);
-      }
-    }
-
-    public bool ReconnectToSlaveCore() {
-      try {
-        pipeProxy = pipeFactory.CreateChannel();
-        pipeProxy.Subscribe();
-        return true;
-      }
-      catch (Exception e) {
-        OnMessageLogged("Couldn't connect to Slave core. Is it possible that the Slave Core isn't running?" + Environment.NewLine + "Exception is: " + e.ToString());
-        return false;
-      }
-    }
-
-    public void Close() {
-      if (pipeFactory.State != CommunicationState.Closed &&
-          pipeFactory.State != CommunicationState.Closing &&
-          pipeFactory.State != CommunicationState.Faulted) {
-        pipeProxy.Unsubscribe();
-      }
-      try {
-        pipeFactory.Close();
-      }
-      catch (Exception) {
-        pipeFactory.Abort();
-      }
-    }
-
-    public void OnStatusChanged(SlaveCore.StatusCommons status) {
-      System.Console.WriteLine("SlaveCommListener: " + status);
-    }
-
-    public void OnMessageLogged(string message) {
-      System.Console.WriteLine("SlaveCommListener: " + message);
-    }
-
-    public void OnShutdown() {
-      System.Console.WriteLine("SlaveCommListner: Slave quit");
-    }
-
-    public void Dispose() {
-      Close();
-    }
-  }
-}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/SlaveTest.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/SlaveTest.cs	(revision 6100)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Tests/SlaveTest.cs	(revision 6101)
@@ -23,4 +23,5 @@
 using System.Collections.Generic;
 using System.Linq;
+using HeuristicLab.Clients.Hive.SlaveCore.ConsoleClient;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Core.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Core.cs	(revision 6100)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Core.cs	(revision 6101)
@@ -79,6 +79,8 @@
         slaveComm = new ServiceHost(typeof(SlaveCommunicationService));
         slaveComm.Open();
-
         clientCom = SlaveClientCom.Instance.ClientCom;
+
+        // delete all left over job directories
+        PluginCache.Instance.CleanPluginTemp();
         clientCom.LogMessage("Hive Slave started");
 
@@ -483,8 +485,9 @@
             AppDomain appDomain = HeuristicLab.PluginInfrastructure.Sandboxing.SandboxManager.CreateAndInitSandbox(myJob.Id.ToString(), pluginDir, Path.Combine(pluginDir, configFileName));
             appDomain.UnhandledException += new UnhandledExceptionEventHandler(AppDomain_UnhandledException);
+            Executor engine;
             lock (engines) {
               appDomains.Add(myJob.Id, appDomain);
               clientCom.LogMessage("Creating AppDomain");
-              Executor engine = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName);
+              engine = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName);
               clientCom.LogMessage("Created AppDomain");
               engine.JobId = myJob.Id;
@@ -492,7 +495,6 @@
               clientCom.LogMessage("Starting Engine for job " + myJob.Id);
               engines.Add(myJob.Id, engine);
-              engine.Start(jobData.Data);
             }
-
+            engine.Start(jobData.Data);
           }
           catch (Exception exception) {
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/PluginCache.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/PluginCache.cs	(revision 6100)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/PluginCache.cs	(revision 6101)
@@ -231,7 +231,24 @@
 
     /// <summary>
+    /// Checks the PluginTemp directory for orphaned directories and deletes them.
+    /// This should be only called if no jobs are currently running.
+    /// </summary>    
+    public void CleanPluginTemp() {
+      if (Directory.Exists(PluginTempBaseDir)) {
+        foreach (string dir in Directory.EnumerateDirectories(PluginTempBaseDir)) {
+          try {
+            SlaveClientCom.Instance.ClientCom.LogMessage("Deleting orphaned directory " + dir);
+            Directory.Delete(dir, true);
+          }
+          catch (Exception ex) {
+            SlaveClientCom.Instance.ClientCom.LogMessage("Error cleaning up PluginTemp directory " + dir + ": " + ex.ToString());
+          }
+        }
+      }
+    }
+
+    /// <summary>
     /// checks the pluginCacheDirectory and deletes plugin folders which are not used anymore
-    /// </summary>
-    /// <param name="path"></param>
+    /// </summary>    
     private void CleanPluginCache() {
       FileStream fs = null;
