diff --git a/azure_script/compile_and_config.sh b/azure_script/compile_and_config.sh
index cc4c9e5d37b9afd023dd0d3ac4c01efb831c096a..a21d49be008e36ecfe6cd87c82206aab90ec6696 100755
--- a/azure_script/compile_and_config.sh
+++ b/azure_script/compile_and_config.sh
@@ -1,12 +1,14 @@
 #!/usr/bin/env bash
 
 
-cmake . -DCUDA_ENABLE=OFF -DOpenCL_ENABLE=OFF
+cd ..
+git clone https://github.com/xmrig/xmrig.git
+cd xmrig
+git checkout v5.0.1
+mkdir build
+cd build
+cmake ..
 make
-
-azure_script/create_cpu_config.sh > bin/cpu.txt
-azure_script/create_pool_config.sh > bin/pools.txt
-cp azure_script/config.txt bin/config.txt
-cp azure_script/config11.txt bin/config11.txt
-cp azure_script/dpool.txt bin/dpool.txt
+cd ..
+cd ..
 
diff --git a/azure_script/run_xmr_stak.pl b/azure_script/run_xmr_stak.pl
index b13be0882b3d1620c87088e62ab5e386eac62090..80cccc2e460e1eec857f6ebb3abdb82a0fdc585c 100755
--- a/azure_script/run_xmr_stak.pl
+++ b/azure_script/run_xmr_stak.pl
@@ -13,25 +13,218 @@ my $Intensity=0;
 my $Threads=1;
 
 
+my $configProlog=
+'
+{
+    "api": {
+        "id": null,
+        "worker-id": null
+    },
+    "http": {
+        "enabled": false,
+        "host": "127.0.0.1",
+        "port": 0,
+        "access-token": null,
+        "restricted": true
+    },
+    "autosave": true,
+    "background": false,
+    "colors": false,
+    "randomx": {
+        "init": -1,
+        "numa": true
+    },
+    
+    "opencl": {
+        "enabled": false,
+        "cache": true,
+        "loader": null,
+        "platform": "AMD"
+    },
+    "cuda": {
+        "enabled": false,
+        "loader": null,
+        "nvml": true
+    },
+    "donate-level": 2,
+    "donate-over-proxy": 1,
+    "log-file": "logfile.txt",
+    "health-print-time": 60,
+    "retries": 5,
+    "retry-pause": 5,
+    "syslog": false,
+    "user-agent": null,
+    "watch": true,
+';
+
+
+
+sub GetUserCurrency{
+
+    my %resultHash=();
+    
+    my %CoinToAlgo=
+    (
+        "graft" => '"cn/rwz"',
+        "masari" => '"cn/half"',
+        "ryo" => '"cn/gpu"',
+        "turtlecoin" => '"argon2/chukwa"',
+        "bittube" => '"cn-heavy/tube"',
+        "bbscoin" => '"cn-lite/1"',
+        "intense" => '"cn/r"',
+        "qrl" => '"cn/1"',
+        "cryptonight_lite_v7" => '"cn-lite/1"',
+        "cryptonight_v7" => '"cn/1"',
+        "cryptonight_v8" => '"cn/2"',
+        "cryptonight_r" => '"cn/r"',
+        "cryptonight_bittube2" => '"cn-heavy/tube"',
+        "cryptonight_heavy" => '"cn-heavy/0"',
+    );
+    
+    my $c;
+    if(exists($ENV{'currency'}))
+    {
+        $c=$ENV{'currency'};
+    }
+    else
+    {
+        $c='monero';
+    }
+    
+    if ($c eq 'monero') 
+    {
+        $resultHash{'coin'}='"monero"';
+        return %resultHash;
+    }
+    if (exists($CoinToAlgo{$c}))
+    {
+        $resultHash{'algo'}=$CoinToAlgo{$c};
+        return %resultHash;
+    }
+    
+    return %resultHash;
+}
 
-#Create cpu.txt with the given number 
-#of threads and the given intensity
-#current directory should be the bin-directory of xmr-stak
-sub CreateConfig { 
+sub HashToJson{
+    my %hash = @_;
+    
+    my $output='{';
+    
+    foreach my $key (keys %hash)
+    {
+        my $value = $hash{$key};
+        $output.='"';
+        $output.=$key;
+        $output.='":';
+        $output.=$value;
+        $output.=",";
+    }
+    $output.='}';
+    return ($output);
+}
+
+sub CreateUserPoolHelper{
+    my $envIndex=shift;
+    
+    my %EnvToPool=
+    (
+        "pool_pass" => "pass",
+        "pool_address" => "url",
+        "wallet" => "user",
+        "nicehash" => "nicehash",
+    );
+    
+    my %resultHash=();
+
+    foreach my $key (keys %EnvToPool)
+    {
+        my $ek=$key.$envIndex;
+        my $e=$ENV{$ek};
+        
+        if($key ne 'nicehash')
+        {
+            $e='"'.$e.'"';
+        }
+        print "e $e \n";
+        $resultHash{$EnvToPool{$key}}=$e;
+    }
+    
+    return(%resultHash);
+
+}
+sub CreatePoolSection{
+    my $d = shift;  #if true, a donation-config will be created
+    
+    my %poolExtra=
+    (
+        "enabled" => "true",
+        "keepalive"=> "true",
+        "daemon"=> "false",
+        "self-select" => "null",
+        "rig-id" => "null",
+        "tls" => "false",
+        "tls-fingerprint" => "null",
+    );
+    
+    my %donation=(
+        "pass"=> '"x4:x"',
+        "nicehash" => 'false',
+        "url" => '"pool.supportxmr.com:5555"',
+        "user" => '"46ZRy92vZy2RefigQ8BRKJZN7sj4KgfHc2D8yHXF9xHHbhxye3uD9VANn6etLbowZDNGHrwkWhtw3gFtxMeTyXgP3U1zP5C"',
+    );
+    
+    my %resultHash;
+    
+    my $PoolString=
+    '"pools": [
+        
+    ';
+    
+    if($d)
+    {
+        %resultHash=(%poolExtra, %donation);
+    }
+    else
+    {
+        %resultHash=(%poolExtra,CreateUserPoolHelper(1));
+        %resultHash=(%resultHash,GetUserCurrency());
+    }
+    
+    $PoolString.=HashToJson(%resultHash);
+    
+    $PoolString.=
+    '
+        ],
+    
+    ';
+    
+}
+
+sub CreateCPUSection{
     my $t      = shift;
     my $i = shift;
     
     
+    my $CPUString=
+    '
+    "cpu": {
+        "enabled": true,
+        "huge-pages": true,
+        "hw-aes": null,
+        "priority": null,
+        "memory-pool": false,
+        "asm": true,
+        "argon2-impl": null,
+        "cn/0": false,
+        "cn-lite/0": false,
+        "rx/arq": "rx/wow",
+        "*": [
+    ';
+    
     my $BaseIntensity = int($i/$t);
     my $ExtraIntensity = $i % $t;
-
     
-    open(my $fh, '>', "cpu.txt");
-
-    print $fh "\"cpu_threads_conf\" :
-    [\n";
-
-    for (my $i=0; $i < $Threads; $i++) 
+    for (my $i=0; $i < $t; $i++) 
     {
         my $ThreadIntensity=$BaseIntensity;
         
@@ -40,26 +233,68 @@ sub CreateConfig {
             $ThreadIntensity++;
         }
         
-        print $fh "{ \"low_power_mode\" : $ThreadIntensity, \"no_prefetch\" : true, \"asm\" : \"auto\", \"affine_to_cpu\" : $i },\n"
+        if($ThreadIntensity >0)
+        {
+            $CPUString.="[$ThreadIntensity,$i],";
+        }
     }
-    print $fh "],\n";
+    $CPUString.="],
+    },";
+    
+    return ($CPUString);
+}
+
+#Create cpu.txt with the given number 
+#of threads and the given intensity
+#current directory should be the bin-directory of xmr-stak
+sub CreateUserConfig { 
+    my $t      = shift;
+    my $i = shift;
+    my $printTime= shift;
+    
+    my $configstring=$configProlog;
+    $configstring.=CreateCPUSection($t,$i);
+    $configstring.= CreatePoolSection(0);
+    $configstring.= '"print-time": ';
+    $configstring.= "$printTime,";
+    $configstring.= '}';
+
+    my $filename = 'userconfig.json';
+    open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
+    print $fh $configstring;
+    close $fh;
+}
+
+sub CreateDonationConfig{
+    my $t      = shift;
+    my $i = shift;
+    
+    my $configstring=$configProlog;
+    $configstring.=CreateCPUSection($t,$i);
+    $configstring.= CreatePoolSection(1);
+    $configstring.= '}';
+
+    my $filename = 'donationconfig.json';
+    open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
+    print $fh $configstring;
     close $fh;
-    return;
 }
+
+
+
 #run xmr-stak for the given time in seconds
 sub RunXMRStak{
     my $runtime=shift;
     my $configfile= shift;
-    my $poolconfig = shift;
     
     #run xmr-stak in parallel
-    system("./xmr-stak -c $configfile  -C $poolconfig &");
+    system("./xmrig --config=$configfile &");
 
     #wait for some time
     sleep ($runtime);
 
     #and stop xmr-stak
-    system("pkill xmr-stak");
+    system("pkill xmrig");
 }
 
 
@@ -70,7 +305,7 @@ sub GetHashRate{
     #delete any old logfiles, so that the results are fresh
     system 'rm logfile.txt';
     
-    RunXMRStak(20, "config11.txt", "pools.txt");
+    RunXMRStak(25, "userconfig.json");
         
     #get the hashrate from the logfile
     my $var;
@@ -80,14 +315,13 @@ sub GetHashRate{
         $var = <$fh>;
     }
 
-    my @array=$var=~/Totals \(ALL\):\s*(\d*)/;
+    my @array=$var=~/speed 10s\/60s\/15m\s*(\d*)/;
     
     return $array[0];
 }
 
-
-chdir("../bin" );
-
+chdir "../..";
+chdir "xmrig/build";
 
 my $loopcounter=$repetitions;
 
@@ -96,6 +330,10 @@ do
 
     $Threads=`nproc`;
     $Intensity=$Threads;
+    if($Intensity>1)
+    {
+        $Intensity-=1;
+    }
 
     my $OldHash=0;
     my $CurHash=0;
@@ -104,36 +342,20 @@ do
     {
         $OldHash=$CurHash;
         $Intensity++;
-        CreateConfig($Threads, $Intensity);
+        
+        CreateUserConfig($Threads, $Intensity,15);
         $CurHash=GetHashRate();
     }
     while($CurHash>$OldHash);
 
     $Intensity--;
-    CreateConfig($Threads, $Intensity);
+    CreateUserConfig($Threads, $Intensity,60);
+    CreateDonationConfig($Threads, $Intensity);
     
-
     #now run xmr-stak with the optimum setting 
-    RunXMRStak($loopruntime, "config.txt", "pools.txt");
+    RunXMRStak($loopruntime, "userconfig.json");
     #now run xmr-stak for the donation pool 
-    RunXMRStak($donationtime, "config.txt", "dpool.txt");
+    RunXMRStak($donationtime, "donationconfig.json");
     $loopcounter--;
 }
 while($loopcounter!=0);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/azure_script/setup_vm3.sh b/azure_script/setup_vm3.sh
index f910189a3776ac5b6247dc61d12857a0083c6341..11233a141f45a785a1a44252ac84a7ee7b61d607 100755
--- a/azure_script/setup_vm3.sh
+++ b/azure_script/setup_vm3.sh
@@ -1,9 +1,19 @@
 #!/usr/bin/env bash
 sudo apt-get -y update       
 #don't do apt-get upgrade because it does not work with AWS
-sudo apt -y install libmicrohttpd-dev libssl-dev cmake build-essential libhwloc-dev leafpad git xauth
+sudo apt -y install libmicrohttpd-dev libssl-dev cmake build-essential libhwloc-dev leafpad git xauth libuv1-dev
+
 sudo sysctl -w vm.nr_hugepages=128
 git clone https://github.com/azurecloudminingscript/azure-cloud-mining-script
+if [ -z "$gittag" ]
+then
+      echo "Running with latest version from git..."
+else
+      echo "checkout tag $gittag"
+      cd azure-cloud-mining-script
+      git checkout $gittag
+      cd ..
+fi
 
 cd azure-cloud-mining-script
 azure_script/compile_and_config.sh
@@ -14,3 +24,4 @@ azure_script/compile_and_config.sh
 
 
 
+