Copy changes in PMGTools from branch 21.2 and fix minor things to make it compile without warnings and errors