 
   def activate(name) do
     GenServer.call(Boyle, {:activate, name})
-    # reinstall()
+    reinstall()
   end
 
   def deactivate do
-    GenServer.call(Boyle, {:activate, nil})
     Mix.Project.pop()
     Mix.Task.clear()
     # Mix.Shell.Process.flush()
     Mix.ProjectStack.clear_cache()
     # Mix.ProjectStack.clear_stack()
+    env_path_trimmed = Path.join("envs", active_env_name())
     :code.get_path |> Enum.map(fn path ->
-      if path not in state().initial_paths do
+      # if path not in state().initial_paths do
+      if String.contains?(to_string(path), env_path_trimmed) do
         Code.delete_path(path)
-        end
+        Logger.debug("Removed path #{to_string(path)}")
+      end
     end)
     :code.all_loaded |> Enum.map(fn {module, path} ->
-      if {module, path} not in state().initial_modules do
-        # IO.puts(to_string(module) <> " : " <> to_string(path))
+      # if {module, path} not in state().initial_modules and
+      if String.contains?(to_string(path), env_path_trimmed) do
         purge([module])
-      end
-    end)
-    # :code.get_path() |> Enum.map(fn path ->
-		# 	if String.contains?(to_string(path), [environment_path()]) do
-		# 		Code.delete_path(path)
-		# 	end
-		# end)
+        Logger.debug("Purged module #{to_string(module)} : #{to_string(path)}")
+      end
+    end)
+    GenServer.call(Boyle, {:activate, nil})
   end
 
   def install(new_dep) do

    GenServer.call(Boyle, :get_state)
  end

  def reinstall do
    Mix.start()
    Mix.Project.pop()

    File.cd!(environment_path(), fn ->
      # Code.require_file("mix.exs")
      Code.load_file("mix.exs")
      # Mix.Project.push(CustomEnvironment)
      # IO.inspect(CustomEnvironment.project())
      Mix.Task.run("deps.get")
      Mix.Tasks.Deps.Compile.run([])
    end)
  end

  def paths do

          deps
        end)
    end
  end

  defp create_mix_exs_file(env_path) do
