diff --git a/project/Build.scala b/project/Build.scala
index 81e56fdaabc1cde4e860764aa954763d9a053633..43a54c499148c0558927900ff1ba127d86e1fcd4 100644
--- a/project/Build.scala
+++ b/project/Build.scala
@@ -4,7 +4,11 @@ import Keys._
 
 object Leon extends Build {
   private val scriptName = "leon"
-  def scriptFile = file(".") / scriptName
+  private val setupScriptName = "setupenv"
+
+  def scriptFile      = file(".") / scriptName
+  def setupScriptFile = file(".") / setupScriptName
+
   def is64 = System.getProperty("sun.arch.data.model") == "64"
   def ldLibraryDir32 = file(".") / "lib-bin" / "32"
   def ldLibraryDir64 = file(".") / "lib-bin" / "64"
@@ -16,7 +20,7 @@ object Leon extends Build {
     }
   }
 
-  val scriptTask = TaskKey[Unit]("script", "Generate the " + scriptName + " Bash script") <<= (streams, dependencyClasspath in Compile, classDirectory in Compile) map { (s, deps, out) =>
+  val scriptTask = TaskKey[Unit]("script", "Generate the " + scriptName + " and " + setupScriptName + " Bash scriptes") <<= (streams, dependencyClasspath in Compile, classDirectory in Compile) map { (s, deps, out) =>
     if(scriptFile.exists) {
       s.log.info("Re-generating script ("+(if(is64) "64b" else "32b")+")...")
       scriptFile.delete
@@ -36,13 +40,13 @@ object Leon extends Build {
       val nl = System.getProperty("line.separator")
       val fw = new java.io.FileWriter(scriptFile)
       fw.write("#!/bin/bash --posix" + nl)
-      if (is64) {
+      val ldLibPath = if (is64) {
         fw.write("SCALACLASSPATH=\"")
         fw.write((out.absolutePath +: depsPaths).mkString(":"))
         fw.write("\"" + nl + nl)
 
         // Setting the dynamic lib path
-        fw.write("LIBRARY_PATH=\"" + ldLibraryDir64.absolutePath + "\"" + nl)
+        ldLibraryDir64.absolutePath
       } else {
         fw.write("if [ `uname -m` == \"x86_64\" ]; then "+nl)
 
@@ -56,12 +60,18 @@ object Leon extends Build {
           fw.write("\"" + nl)
 
           // Setting the dynamic lib path
-          fw.write("    LIBRARY_PATH=\"" + ldLibraryDir32.absolutePath + "\"" + nl)
         fw.write("fi" + nl + nl)
+
+        ldLibraryDir32.absolutePath
       }
 
+      val leonLibPath = depsPaths.find(_.endsWith("/library/target/scala-2.9.2/classes")) match {
+        case None => throw new Exception("Couldn't find leon-library in the classpath.")
+        case Some(p) => p
+      }
+
+      fw.write("source "+setupScriptFile.getAbsolutePath()+nl)
       // the Java command that uses sbt's local Scala to run the whole contraption.
-      fw.write("LD_LIBRARY_PATH=\"$LIBRARY_PATH\" \\"+nl)
       fw.write("java -Xmx2G -Xms512M -classpath ${SCALACLASSPATH} -Dscala.home=\"")
       fw.write(scalaHomeDir)
       fw.write("\" -Dscala.usejavacp=true ")
@@ -69,6 +79,16 @@ object Leon extends Build {
       fw.write("leon.Main $@" + nl)
       fw.close
       scriptFile.setExecutable(true)
+
+      s.log.info("Generating setup script ("+(if(is64) "64b" else "32b")+")...")
+      val sfw = new java.io.FileWriter(setupScriptFile)
+      sfw.write("#!/bin/bash --posix" + nl)
+      sfw.write("export LD_LIBRARY_PATH=\""+ldLibPath+"\"" + nl)
+      sfw.write("export LEON_LIBRARY_PATH=\""+leonLibPath+"\"" + nl)
+      sfw.write("export SCALA_HOME=\""+scalaHomeDir+"\"" + nl)
+      sfw.close
+      setupScriptFile.setExecutable(true)
+
     } catch {
       case e => s.log.error("There was an error while generating the script file: " + e.getLocalizedMessage)
     }
diff --git a/src/main/scala/leon/Settings.scala b/src/main/scala/leon/Settings.scala
index 5a56cbb71aaef4030b3eb1ac75864c99982a54d5..754fbde7fff21aefc8398598e4fa2c685616e31f 100644
--- a/src/main/scala/leon/Settings.scala
+++ b/src/main/scala/leon/Settings.scala
@@ -9,12 +9,26 @@ object Settings {
   var silentlyTolerateNonPureBodies: Boolean = false
 
   def defaultClassPath() = {
-    val env = System.getenv("SCALA_HOME")
-    if (env != "") {
-      List(env+"/lib")
+    val leonLib = System.getenv("LEON_LIBRARY_PATH")
+    if (leonLib == "" || leonLib == null) {
+      sys.error("LEON_LIBRARY_PATH env variable is undefined")
+    }
+
+    val leonCPs = leonLib
+
+    val scalaHome = System.getenv("SCALA_HOME")
+    val scalaCPs = if (scalaHome != "") {
+      val f = new java.io.File(scalaHome+"/lib")
+
+      f.listFiles().collect {
+        case f if f.getPath().endsWith(".jar") => f.getAbsolutePath()
+      }.toList
+
     } else {
       Nil
     }
+
+    leonCPs :: scalaCPs
   }
 }
 
diff --git a/src/main/scala/leon/plugin/ExtractionPhase.scala b/src/main/scala/leon/plugin/ExtractionPhase.scala
index 1c788def1c1e6950ba0a7180caf1baa28f576538..c68f7f6b81e792197c3099b0f2eec769ca073a7d 100644
--- a/src/main/scala/leon/plugin/ExtractionPhase.scala
+++ b/src/main/scala/leon/plugin/ExtractionPhase.scala
@@ -13,8 +13,7 @@ object ExtractionPhase extends LeonPhase[List[String], Program] {
 
     val settings = new NSCSettings
 
-    //settings.extdirs.value = ctx.settings.classPath.mkString(":")
-    settings.usejavacp.value = true
+    settings.classpath.value = ctx.settings.classPath.mkString(":")
 
     val compilerOpts = args.filterNot(_.startsWith("--"))
 
@@ -26,7 +25,7 @@ object ExtractionPhase extends LeonPhase[List[String], Program] {
       // Debugging code for classpath crap
       // new scala.tools.util.PathResolver(settings).Calculated.basis.foreach { cp =>
       //   cp.foreach( p =>
-      //     ctx.reporter.info(" => "+p.toString)
+      //     println(" => "+p.toString)
       //   )
       // }